• 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_LOGD("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     if (result != TELEPHONY_ERR_SUCCESS) {
321         TELEPHONY_LOGE("OnSetCBConfig fail, result:%{public}d, slotId:%{public}d", result, slotId);
322     }
323     reply.WriteInt32(result);
324 }
325 
OnSetImsSmsConfig(MessageParcel & data,MessageParcel & reply,MessageOption & option)326 void SmsInterfaceStub::OnSetImsSmsConfig(MessageParcel &data, MessageParcel &reply, MessageOption &option)
327 {
328     bool result = false;
329     int32_t slotId = data.ReadInt32();
330     int32_t enable = data.ReadInt32();
331     result = SetImsSmsConfig(slotId, enable);
332     TELEPHONY_LOGI("SetImsSmsConfig result %{public}d", result);
333     reply.WriteBool(result);
334 }
335 
OnSetDefaultSmsSlotId(MessageParcel & data,MessageParcel & reply,MessageOption & option)336 void SmsInterfaceStub::OnSetDefaultSmsSlotId(MessageParcel &data, MessageParcel &reply, MessageOption &option)
337 {
338     int32_t slotId = data.ReadInt32();
339     int32_t result = SetDefaultSmsSlotId(slotId);
340     TELEPHONY_LOGI("SetDefaultSmsSlotId result %{public}d", result);
341     reply.WriteInt32(result);
342 }
343 
OnGetDefaultSmsSlotId(MessageParcel & data,MessageParcel & reply,MessageOption & option)344 void SmsInterfaceStub::OnGetDefaultSmsSlotId(MessageParcel &data, MessageParcel &reply, MessageOption &option)
345 {
346     int32_t result = 0;
347     result = GetDefaultSmsSlotId();
348     TELEPHONY_LOGI("SetDefaultSmsSlotId result %{public}d", result);
349     reply.WriteInt32(result);
350 }
351 
OnGetDefaultSmsSimId(MessageParcel & data,MessageParcel & reply,MessageOption & option)352 void SmsInterfaceStub::OnGetDefaultSmsSimId(MessageParcel &data, MessageParcel &reply, MessageOption &option)
353 {
354     int32_t result = 0;
355     int32_t simId = 0;
356     result = GetDefaultSmsSimId(simId);
357     if (!reply.WriteInt32(result)) {
358         TELEPHONY_LOGE("write int32 reply failed.");
359         return;
360     }
361     if (result != TELEPHONY_ERR_SUCCESS) {
362         TELEPHONY_LOGE("result %{public}d", result);
363         return;
364     }
365     if (!reply.WriteInt32(simId)) {
366         TELEPHONY_LOGE("write int32 reply failed.");
367         return;
368     }
369 }
370 
OnSplitMessage(MessageParcel & data,MessageParcel & reply,MessageOption & option)371 void SmsInterfaceStub::OnSplitMessage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
372 {
373     std::vector<std::u16string> splitMessage;
374     std::u16string message = data.ReadString16();
375     int32_t result = SplitMessage(message, splitMessage);
376     reply.WriteInt32(result);
377     if (result != TELEPHONY_ERR_SUCCESS) {
378         TELEPHONY_LOGE("SmsInterfaceStub::OnSplitMessage result is not TELEPHONY_ERR_SUCCESS.");
379         return;
380     }
381     int32_t resultLen = static_cast<int32_t>(splitMessage.size());
382     TELEPHONY_LOGI("SplitMessage size %{public}d", resultLen);
383     reply.WriteInt32(resultLen);
384     for (const auto &item : splitMessage) {
385         reply.WriteString16(item);
386     }
387 }
388 
OnGetSmsSegmentsInfo(MessageParcel & data,MessageParcel & reply,MessageOption & option)389 void SmsInterfaceStub::OnGetSmsSegmentsInfo(MessageParcel &data, MessageParcel &reply, MessageOption &option)
390 {
391     int32_t slotId = data.ReadInt32();
392     std::u16string message = data.ReadString16();
393     bool force7BitCode = data.ReadBool();
394 
395     SmsSegmentsInfo segInfo;
396     int32_t result = GetSmsSegmentsInfo(slotId, message, force7BitCode, segInfo);
397     reply.WriteInt32(result);
398 
399     if (result == TELEPHONY_ERR_SUCCESS) {
400         reply.WriteInt32(segInfo.msgSegCount);
401         reply.WriteInt32(segInfo.msgEncodingCount);
402         reply.WriteInt32(segInfo.msgRemainCount);
403         reply.WriteInt32(static_cast<int32_t>(segInfo.msgCodeScheme));
404     }
405 }
406 
OnIsImsSmsSupported(MessageParcel & data,MessageParcel & reply,MessageOption & option)407 void SmsInterfaceStub::OnIsImsSmsSupported(MessageParcel &data, MessageParcel &reply, MessageOption &option)
408 {
409     int32_t slotId = data.ReadInt32();
410     bool isSupported = false;
411     int32_t result = IsImsSmsSupported(slotId, isSupported);
412     if (!reply.WriteInt32(result)) {
413         TELEPHONY_LOGE("SmsInterfaceStub::OnIsImsSmsSupported write reply failed.");
414         return;
415     }
416     if (result != TELEPHONY_ERR_SUCCESS) {
417         TELEPHONY_LOGE("SmsInterfaceStub::OnIsImsSmsSupported result is not TELEPHONY_ERR_SUCCESS.");
418         return;
419     }
420     if (!reply.WriteBool(isSupported)) {
421         TELEPHONY_LOGE("SmsInterfaceStub::OnIsImsSmsSupported write reply failed.");
422         return;
423     }
424 }
425 
OnGetImsShortMessageFormat(MessageParcel & data,MessageParcel & reply,MessageOption & option)426 void SmsInterfaceStub::OnGetImsShortMessageFormat(MessageParcel &data, MessageParcel &reply, MessageOption &option)
427 {
428     std::u16string format;
429     int32_t result = GetImsShortMessageFormat(format);
430     reply.WriteInt32(result);
431     if (result != TELEPHONY_ERR_SUCCESS) {
432         TELEPHONY_LOGE("SmsInterfaceStub::OnGetImsShortMessageFormat result is not TELEPHONY_ERR_SUCCESS.");
433         return;
434     }
435     reply.WriteString16(format);
436 }
437 
OnHasSmsCapability(MessageParcel & data,MessageParcel & reply,MessageOption & option)438 void SmsInterfaceStub::OnHasSmsCapability(MessageParcel &data, MessageParcel &reply, MessageOption &option)
439 {
440     reply.WriteBool(HasSmsCapability());
441 }
442 
OnCreateMessage(MessageParcel & data,MessageParcel & reply,MessageOption & option)443 void SmsInterfaceStub::OnCreateMessage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
444 {
445     std::string pdu = data.ReadString();
446     std::string specification = data.ReadString();
447     ShortMessage message;
448     int32_t result = CreateMessage(pdu, specification, message);
449 
450     reply.WriteInt32(result);
451     if (result != TELEPHONY_ERR_SUCCESS) {
452         return;
453     }
454     if (!message.Marshalling(reply)) {
455         TELEPHONY_LOGE("SmsInterfaceStub::OnCreateMessage fail");
456     }
457 }
458 
OnGetBase64Encode(MessageParcel & data,MessageParcel & reply,MessageOption & option)459 void SmsInterfaceStub::OnGetBase64Encode(MessageParcel &data, MessageParcel &reply, MessageOption &option)
460 {
461     bool result = false;
462 
463     u16string src = data.ReadString16();
464     std::string dest;
465     result = GetBase64Encode(StringUtils::ToUtf8(src), dest);
466     reply.WriteBool(result);
467     if (!result) {
468         return;
469     }
470     reply.WriteString16(StringUtils::ToUtf16(dest));
471 }
472 
OnGetBase64Decode(MessageParcel & data,MessageParcel & reply,MessageOption & option)473 void SmsInterfaceStub::OnGetBase64Decode(MessageParcel &data, MessageParcel &reply, MessageOption &option)
474 {
475     bool result = false;
476     u16string src = data.ReadString16();
477     std::string dest;
478     result = GetBase64Decode(StringUtils::ToUtf8(src), dest);
479     reply.WriteBool(result);
480     if (!result) {
481         return;
482     }
483     reply.WriteString16(StringUtils::ToUtf16(dest));
484 }
485 
OnGetEncodeStringFunc(MessageParcel & data,MessageParcel & reply,MessageOption & option)486 void SmsInterfaceStub::OnGetEncodeStringFunc(MessageParcel &data, MessageParcel &reply, MessageOption &option)
487 {
488     bool result = false;
489     uint32_t charset = data.ReadUint32();
490     uint32_t valLength = data.ReadUint32();
491     u16string strEncodeString = data.ReadString16();
492     std::string str = StringUtils::ToUtf8(strEncodeString);
493     std::string encodeString;
494 
495     if (valLength != str.length()) {
496         TELEPHONY_LOGE("invalid valLength!");
497         return;
498     }
499     result = GetEncodeStringFunc(encodeString, charset, valLength, str);
500     reply.WriteBool(result);
501     if (!result) {
502         return;
503     }
504     reply.WriteString16(StringUtils::ToUtf16(encodeString));
505 }
506 
OnSendMms(MessageParcel & data,MessageParcel & reply,MessageOption & option)507 void SmsInterfaceStub::OnSendMms(MessageParcel &data, MessageParcel &reply, MessageOption &option)
508 {
509     int32_t slotId = data.ReadInt32();
510     TELEPHONY_LOGI("send mms slotId:%{public}d", slotId);
511     u16string mmsc = data.ReadString16();
512     u16string mmsData = data.ReadString16();
513     u16string ua = data.ReadString16();
514     u16string uaprof = data.ReadString16();
515     int32_t result = SendMms(slotId, mmsc, mmsData, ua, uaprof);
516     if (!reply.WriteInt32(result)) {
517         TELEPHONY_LOGE("SmsInterfaceStub::OnSendMms write reply failed");
518         return;
519     }
520 }
521 
OnDownloadMms(MessageParcel & data,MessageParcel & reply,MessageOption & option)522 void SmsInterfaceStub::OnDownloadMms(MessageParcel &data, MessageParcel &reply, MessageOption &option)
523 {
524     int32_t slotId = data.ReadInt32();
525     TELEPHONY_LOGI("download mms slotId:%{public}d", slotId);
526     u16string mmsc = data.ReadString16();
527     u16string mmsData = data.ReadString16();
528     u16string ua = data.ReadString16();
529     u16string uaprof = data.ReadString16();
530     int32_t result = DownloadMms(slotId, mmsc, mmsData, ua, uaprof);
531     if (!reply.WriteInt32(result)) {
532         TELEPHONY_LOGE("SmsInterfaceStub::OnDownloadMms write reply failed");
533         return;
534     }
535     reply.WriteString16(mmsData);
536     TELEPHONY_LOGI("SmsInterfaceStub::OnDownloadMms dbUrls:%{public}s", StringUtils::ToUtf8(mmsData).c_str());
537 }
538 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)539 int SmsInterfaceStub::OnRemoteRequest(
540     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
541 {
542     TELEPHONY_LOGD("SmsInterfaceStub::OnRemoteRequest code:%{public}d", code);
543     std::u16string myDescripter = SmsInterfaceStub::GetDescriptor();
544     std::u16string remoteDescripter = data.ReadInterfaceToken();
545     if (myDescripter != remoteDescripter) {
546         TELEPHONY_LOGE("descriptor checked fail");
547         return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
548     }
549 
550     auto itFunc = memberFuncMap_.find(code);
551     if (itFunc != memberFuncMap_.end()) {
552         auto memberFunc = itFunc->second;
553         if (memberFunc != nullptr) {
554             (this->*memberFunc)(data, reply, option);
555             return TELEPHONY_ERR_SUCCESS;
556         }
557     }
558     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
559 }
560 } // namespace Telephony
561 } // namespace OHOS
562