• 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         bInitModule = true;
91         std::lock_guard<std::mutex> lock(mutex_);
92         for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; ++slotId) {
93             slotSmsInterfaceManagerMap_[slotId] = std::make_shared<SmsInterfaceManager>(slotId);
94             if (slotSmsInterfaceManagerMap_[slotId] == nullptr) {
95                 TELEPHONY_LOGE(
96                     "SmsInterfaceStub InitModule slotSmsInterfaceManagerMap_[%{public}d] is nullptr", slotId);
97                 return;
98             }
99             slotSmsInterfaceManagerMap_[slotId]->InitInterfaceManager();
100 
101             std::thread smsReceiveReliabilityTask([slotId]() {
102                 auto reliabilityHandler = std::make_shared<SmsReceiveReliabilityHandler>(slotId);
103                 if (reliabilityHandler == nullptr) {
104                     TELEPHONY_LOGE("reliabilityHandler nullptr");
105                     return;
106                 }
107                 if (!reliabilityHandler->DeleteExpireSmsFromDB()) {
108                     TELEPHONY_LOGE("DeleteExpireSmsFromDB fail");
109                     return;
110                 }
111                 if (!reliabilityHandler->CheckSmsCapable()) {
112                     TELEPHONY_LOGE("sms receive capable unSupport");
113                     return;
114                 }
115                 reliabilityHandler->SmsReceiveReliabilityProcessing();
116             });
117             pthread_setname_np(smsReceiveReliabilityTask.native_handle(), "sms_receive_reliability");
118             smsReceiveReliabilityTask.detach();
119         }
120     }
121 }
122 
GetSmsInterfaceManager(int32_t slotId)123 std::shared_ptr<SmsInterfaceManager> SmsInterfaceStub::GetSmsInterfaceManager(int32_t slotId)
124 {
125     std::lock_guard<std::mutex> lock(mutex_);
126     std::map<uint32_t, std::shared_ptr<SmsInterfaceManager>>::iterator iter =
127         slotSmsInterfaceManagerMap_.find(slotId);
128     if (iter != slotSmsInterfaceManagerMap_.end()) {
129         return iter->second;
130     }
131     return nullptr;
132 }
133 
GetSmsInterfaceManager()134 std::shared_ptr<SmsInterfaceManager> SmsInterfaceStub::GetSmsInterfaceManager()
135 {
136     std::lock_guard<std::mutex> lock(mutex_);
137     for (const auto &iter : slotSmsInterfaceManagerMap_) {
138         if (iter.second != nullptr) {
139             return iter.second;
140         }
141     }
142     return nullptr;
143 }
144 
OnSendSmsTextRequest(MessageParcel & data,MessageParcel & reply,MessageOption & option)145 void SmsInterfaceStub::OnSendSmsTextRequest(MessageParcel &data, MessageParcel &reply, MessageOption &option)
146 {
147     sptr<ISendShortMessageCallback> sendCallback = nullptr;
148     sptr<IDeliveryShortMessageCallback> deliveryCallback = nullptr;
149     int32_t slotId = data.ReadInt32();
150     u16string desAddr = data.ReadString16();
151     u16string scAddr = data.ReadString16();
152     u16string text = data.ReadString16();
153     if (!IsValidSlotId(slotId)) {
154         TELEPHONY_LOGE("invalid slotId:%{public}d", slotId);
155         return;
156     }
157 
158     sptr<IRemoteObject> remoteSendCallback = data.ReadRemoteObject();
159     sptr<IRemoteObject> remoteDeliveryCallback = data.ReadRemoteObject();
160     if (remoteSendCallback != nullptr) {
161         sendCallback = iface_cast<ISendShortMessageCallback>(remoteSendCallback);
162     }
163     if (remoteDeliveryCallback != nullptr) {
164         deliveryCallback = iface_cast<IDeliveryShortMessageCallback>(remoteDeliveryCallback);
165     }
166     TELEPHONY_LOGI("MessageID::TEXT_BASED_SMS_DELIVERY %{public}d", slotId);
167     RemoveSpacesInDesAddr(desAddr);
168     std::string bundleName = data.ReadString();
169     TELEPHONY_LOGI("bundleName = %{public}s", bundleName.c_str());
170     int32_t result = SendMessage(slotId, desAddr, scAddr, text, sendCallback, deliveryCallback);
171     if (bundleName != MMS_APP && result == TELEPHONY_ERR_SUCCESS) {
172         DelayedSingleton<SmsService>::GetInstance()->InsertSessionAndDetail(slotId, StringUtils::ToUtf8(desAddr),
173             StringUtils::ToUtf8(text));
174     }
175     reply.WriteInt32(result);
176 }
177 
OnSendSmsDataRequest(MessageParcel & data,MessageParcel & reply,MessageOption & option)178 void SmsInterfaceStub::OnSendSmsDataRequest(MessageParcel &data, MessageParcel &reply, MessageOption &option)
179 {
180     sptr<ISendShortMessageCallback> sendCallback = nullptr;
181     sptr<IDeliveryShortMessageCallback> deliveryCallback = nullptr;
182     int32_t slotId = data.ReadInt32();
183     u16string desAddr = data.ReadString16();
184     u16string scAddr = data.ReadString16();
185     int16_t port = data.ReadInt16();
186     if (!IsValidSlotId(slotId)) {
187         TELEPHONY_LOGE("invalid slotId:%{public}d", slotId);
188         return;
189     }
190 
191     sptr<IRemoteObject> remoteSendCallback = data.ReadRemoteObject();
192     sptr<IRemoteObject> remoteDeliveryCallback = data.ReadRemoteObject();
193     if (remoteSendCallback != nullptr) {
194         sendCallback = iface_cast<ISendShortMessageCallback>(remoteSendCallback);
195     }
196     if (remoteDeliveryCallback != nullptr) {
197         deliveryCallback = iface_cast<IDeliveryShortMessageCallback>(remoteDeliveryCallback);
198     }
199     int16_t dataLen = data.ReadInt16();
200     const uint8_t *buffer = reinterpret_cast<const uint8_t *>(data.ReadRawData(dataLen));
201     RemoveSpacesInDesAddr(desAddr);
202     int32_t result = SendMessage(slotId, desAddr, scAddr, port, buffer, dataLen, sendCallback, deliveryCallback);
203     reply.WriteInt32(result);
204 }
205 
RemoveSpacesInDesAddr(std::u16string & desAddr)206 void SmsInterfaceStub::RemoveSpacesInDesAddr(std::u16string &desAddr)
207 {
208     // Remove spaces in desAddr
209     if (desAddr.empty() || desAddr.size() >= MAX_ADDRESS_LEN) {
210         TELEPHONY_LOGE("RemoveSpacesInDesAddr desAddr is invalid");
211         return;
212     }
213 
214     std::u16string storeAddr = desAddr;
215     int32_t count = static_cast<int32_t>(desAddr.size());
216     int32_t indexDes = 0;
217     int32_t indexResult = 0;
218     while (indexDes < count) {
219         if (desAddr[indexDes] != ' ') {
220             storeAddr[indexResult] = desAddr[indexDes];
221             indexResult++;
222         }
223         indexDes++;
224     }
225     desAddr = storeAddr.substr(0, indexResult);
226 }
227 
OnSetSmscAddr(MessageParcel & data,MessageParcel & reply,MessageOption & option)228 void SmsInterfaceStub::OnSetSmscAddr(MessageParcel &data, MessageParcel &reply, MessageOption &option)
229 {
230     int32_t slotId = data.ReadInt32();
231     std::u16string scAddr = data.ReadString16();
232     int32_t result = SetSmscAddr(slotId, scAddr);
233     TELEPHONY_LOGI("SetSmscAddr result %{public}d", result);
234     reply.WriteInt32(result);
235 }
236 
OnGetSmscAddr(MessageParcel & data,MessageParcel & reply,MessageOption & option)237 void SmsInterfaceStub::OnGetSmscAddr(MessageParcel &data, MessageParcel &reply, MessageOption &option)
238 {
239     std::u16string smscAddress;
240     int32_t slotId = data.ReadInt32();
241     int32_t result = GetSmscAddr(slotId, smscAddress);
242     TELEPHONY_LOGI("GetSmscAddr result size %{public}d", result);
243     if (!reply.WriteInt32(result)) {
244         TELEPHONY_LOGE("SmsInterfaceStub::OnGetSmscAddr write reply failed.");
245         return;
246     }
247     if (result != TELEPHONY_ERR_SUCCESS) {
248         TELEPHONY_LOGE("SmsInterfaceStub::OnGetSmscAddr result is not TELEPHONY_ERR_SUCCESS.");
249         return;
250     }
251 
252     if (!reply.WriteString16(smscAddress)) {
253         TELEPHONY_LOGE("SmsInterfaceStub::OnGetSmscAddr write reply failed.");
254         return;
255     }
256 }
257 
OnAddSimMessage(MessageParcel & data,MessageParcel & reply,MessageOption & option)258 void SmsInterfaceStub::OnAddSimMessage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
259 {
260     int32_t slotId = data.ReadInt32();
261     std::u16string smsc = data.ReadString16();
262     std::u16string pdu = data.ReadString16();
263     uint32_t status = data.ReadUint32();
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     int32_t result = UpdateSimMessage(slotId, msgIndex, static_cast<SimMessageStatus>(newStatus), pdu, smsc);
286     TELEPHONY_LOGI("UpdateSimMessage result %{public}d", result);
287     reply.WriteInt32(result);
288 }
289 
OnGetAllSimMessages(MessageParcel & data,MessageParcel & reply,MessageOption & option)290 void SmsInterfaceStub::OnGetAllSimMessages(MessageParcel &data, MessageParcel &reply, MessageOption &option)
291 {
292     std::vector<ShortMessage> message;
293     int32_t slotId = data.ReadInt32();
294     int32_t result = GetAllSimMessages(slotId, message);
295     TELEPHONY_LOGI("GetAllSimMessages result %{public}d size %{public}zu", result, message.size());
296     reply.WriteInt32(result);
297     if (result != TELEPHONY_ERR_SUCCESS) {
298         TELEPHONY_LOGE("SmsInterfaceStub::OnGetSmscAddr result is not TELEPHONY_ERR_SUCCESS.");
299         return;
300     }
301     int32_t resultLen = static_cast<int32_t>(message.size());
302     reply.WriteInt32(resultLen);
303     for (const auto &v : message) {
304         v.Marshalling(reply);
305     }
306 }
307 
OnSetCBConfig(MessageParcel & data,MessageParcel & reply,MessageOption & option)308 void SmsInterfaceStub::OnSetCBConfig(MessageParcel &data, MessageParcel &reply, MessageOption &option)
309 {
310     int32_t slotId = data.ReadInt32();
311     bool enable = data.ReadBool();
312     uint32_t fromMsgId = data.ReadUint32();
313     uint32_t toMsgId = data.ReadUint32();
314     uint8_t ranType = data.ReadUint8();
315     int32_t result = SetCBConfig(slotId, enable, fromMsgId, toMsgId, ranType);
316     TELEPHONY_LOGI("OnSetCBConfig result %{public}d", result);
317     reply.WriteInt32(result);
318 }
319 
OnSetImsSmsConfig(MessageParcel & data,MessageParcel & reply,MessageOption & option)320 void SmsInterfaceStub::OnSetImsSmsConfig(MessageParcel &data, MessageParcel &reply, MessageOption &option)
321 {
322     bool result = false;
323     int32_t slotId = data.ReadInt32();
324     int32_t enable = data.ReadInt32();
325     result = SetImsSmsConfig(slotId, enable);
326     TELEPHONY_LOGI("SetImsSmsConfig result %{public}d", result);
327     reply.WriteBool(result);
328 }
329 
OnSetDefaultSmsSlotId(MessageParcel & data,MessageParcel & reply,MessageOption & option)330 void SmsInterfaceStub::OnSetDefaultSmsSlotId(MessageParcel &data, MessageParcel &reply, MessageOption &option)
331 {
332     int32_t slotId = data.ReadInt32();
333     int32_t result = SetDefaultSmsSlotId(slotId);
334     TELEPHONY_LOGI("SetDefaultSmsSlotId result %{public}d", result);
335     reply.WriteInt32(result);
336 }
337 
OnGetDefaultSmsSlotId(MessageParcel & data,MessageParcel & reply,MessageOption & option)338 void SmsInterfaceStub::OnGetDefaultSmsSlotId(MessageParcel &data, MessageParcel &reply, MessageOption &option)
339 {
340     int32_t result = 0;
341     result = GetDefaultSmsSlotId();
342     TELEPHONY_LOGI("SetDefaultSmsSlotId result %{public}d", result);
343     reply.WriteInt32(result);
344 }
345 
OnGetDefaultSmsSimId(MessageParcel & data,MessageParcel & reply,MessageOption & option)346 void SmsInterfaceStub::OnGetDefaultSmsSimId(MessageParcel &data, MessageParcel &reply, MessageOption &option)
347 {
348     int32_t result = 0;
349     int32_t simId = 0;
350     result = GetDefaultSmsSimId(simId);
351     if (!reply.WriteInt32(result)) {
352         TELEPHONY_LOGE("write int32 reply failed.");
353         return;
354     }
355     if (result != TELEPHONY_ERR_SUCCESS) {
356         TELEPHONY_LOGE("result %{public}d", result);
357         return;
358     }
359     if (!reply.WriteInt32(simId)) {
360         TELEPHONY_LOGE("write int32 reply failed.");
361         return;
362     }
363 }
364 
OnSplitMessage(MessageParcel & data,MessageParcel & reply,MessageOption & option)365 void SmsInterfaceStub::OnSplitMessage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
366 {
367     std::vector<std::u16string> splitMessage;
368     std::u16string message = data.ReadString16();
369     int32_t result = SplitMessage(message, splitMessage);
370     reply.WriteInt32(result);
371     if (result != TELEPHONY_ERR_SUCCESS) {
372         TELEPHONY_LOGE("SmsInterfaceStub::OnSplitMessage result is not TELEPHONY_ERR_SUCCESS.");
373         return;
374     }
375     int32_t resultLen = static_cast<int32_t>(splitMessage.size());
376     TELEPHONY_LOGI("SplitMessage size %{public}d", resultLen);
377     reply.WriteInt32(resultLen);
378     for (const auto &item : splitMessage) {
379         reply.WriteString16(item);
380     }
381 }
382 
OnGetSmsSegmentsInfo(MessageParcel & data,MessageParcel & reply,MessageOption & option)383 void SmsInterfaceStub::OnGetSmsSegmentsInfo(MessageParcel &data, MessageParcel &reply, MessageOption &option)
384 {
385     int32_t slotId = data.ReadInt32();
386     std::u16string message = data.ReadString16();
387     bool force7BitCode = data.ReadBool();
388 
389     SmsSegmentsInfo segInfo;
390     int32_t result = GetSmsSegmentsInfo(slotId, message, force7BitCode, segInfo);
391     reply.WriteInt32(result);
392 
393     if (result == TELEPHONY_ERR_SUCCESS) {
394         reply.WriteInt32(segInfo.msgSegCount);
395         reply.WriteInt32(segInfo.msgEncodingCount);
396         reply.WriteInt32(segInfo.msgRemainCount);
397         reply.WriteInt32(static_cast<int32_t>(segInfo.msgCodeScheme));
398     }
399 }
400 
OnIsImsSmsSupported(MessageParcel & data,MessageParcel & reply,MessageOption & option)401 void SmsInterfaceStub::OnIsImsSmsSupported(MessageParcel &data, MessageParcel &reply, MessageOption &option)
402 {
403     int32_t slotId = data.ReadInt32();
404     bool isSupported = false;
405     int32_t result = IsImsSmsSupported(slotId, isSupported);
406     if (!reply.WriteInt32(result)) {
407         TELEPHONY_LOGE("SmsInterfaceStub::OnIsImsSmsSupported write reply failed.");
408         return;
409     }
410     if (result != TELEPHONY_ERR_SUCCESS) {
411         TELEPHONY_LOGE("SmsInterfaceStub::OnIsImsSmsSupported result is not TELEPHONY_ERR_SUCCESS.");
412         return;
413     }
414     if (!reply.WriteBool(isSupported)) {
415         TELEPHONY_LOGE("SmsInterfaceStub::OnIsImsSmsSupported write reply failed.");
416         return;
417     }
418 }
419 
OnGetImsShortMessageFormat(MessageParcel & data,MessageParcel & reply,MessageOption & option)420 void SmsInterfaceStub::OnGetImsShortMessageFormat(MessageParcel &data, MessageParcel &reply, MessageOption &option)
421 {
422     std::u16string format;
423     int32_t result = GetImsShortMessageFormat(format);
424     reply.WriteInt32(result);
425     if (result != TELEPHONY_ERR_SUCCESS) {
426         TELEPHONY_LOGE("SmsInterfaceStub::OnGetImsShortMessageFormat result is not TELEPHONY_ERR_SUCCESS.");
427         return;
428     }
429     reply.WriteString16(format);
430 }
431 
OnHasSmsCapability(MessageParcel & data,MessageParcel & reply,MessageOption & option)432 void SmsInterfaceStub::OnHasSmsCapability(MessageParcel &data, MessageParcel &reply, MessageOption &option)
433 {
434     reply.WriteBool(HasSmsCapability());
435 }
436 
OnCreateMessage(MessageParcel & data,MessageParcel & reply,MessageOption & option)437 void SmsInterfaceStub::OnCreateMessage(MessageParcel &data, MessageParcel &reply, MessageOption &option)
438 {
439     std::string pdu = data.ReadString();
440     std::string specification = data.ReadString();
441     ShortMessage message;
442     int32_t result = CreateMessage(pdu, specification, message);
443 
444     reply.WriteInt32(result);
445     if (result != TELEPHONY_ERR_SUCCESS) {
446         return;
447     }
448     if (!message.Marshalling(reply)) {
449         TELEPHONY_LOGE("SmsInterfaceStub::OnCreateMessage fail");
450     }
451 }
452 
OnGetBase64Encode(MessageParcel & data,MessageParcel & reply,MessageOption & option)453 void SmsInterfaceStub::OnGetBase64Encode(MessageParcel &data, MessageParcel &reply, MessageOption &option)
454 {
455     bool result = false;
456 
457     u16string src = data.ReadString16();
458     std::string dest;
459     result = GetBase64Encode(StringUtils::ToUtf8(src), dest);
460     reply.WriteBool(result);
461     if (!result) {
462         return;
463     }
464     reply.WriteString16(StringUtils::ToUtf16(dest));
465 }
466 
OnGetBase64Decode(MessageParcel & data,MessageParcel & reply,MessageOption & option)467 void SmsInterfaceStub::OnGetBase64Decode(MessageParcel &data, MessageParcel &reply, MessageOption &option)
468 {
469     bool result = false;
470     u16string src = data.ReadString16();
471     std::string dest;
472     result = GetBase64Decode(StringUtils::ToUtf8(src), dest);
473     reply.WriteBool(result);
474     if (!result) {
475         return;
476     }
477     reply.WriteString16(StringUtils::ToUtf16(dest));
478 }
479 
OnGetEncodeStringFunc(MessageParcel & data,MessageParcel & reply,MessageOption & option)480 void SmsInterfaceStub::OnGetEncodeStringFunc(MessageParcel &data, MessageParcel &reply, MessageOption &option)
481 {
482     bool result = false;
483     uint32_t charset = data.ReadUint32();
484     uint32_t valLength = data.ReadUint32();
485     u16string strEncodeString = data.ReadString16();
486     std::string str = StringUtils::ToUtf8(strEncodeString);
487     std::string encodeString;
488 
489     if (valLength != str.length()) {
490         TELEPHONY_LOGE("invalid valLength!");
491         return;
492     }
493     result = GetEncodeStringFunc(encodeString, charset, valLength, str);
494     reply.WriteBool(result);
495     if (!result) {
496         return;
497     }
498     reply.WriteString16(StringUtils::ToUtf16(encodeString));
499 }
500 
OnSendMms(MessageParcel & data,MessageParcel & reply,MessageOption & option)501 void SmsInterfaceStub::OnSendMms(MessageParcel &data, MessageParcel &reply, MessageOption &option)
502 {
503     int32_t slotId = data.ReadInt32();
504     u16string mmsc = data.ReadString16();
505     u16string mmsData = data.ReadString16();
506     u16string ua = data.ReadString16();
507     u16string uaprof = data.ReadString16();
508     int32_t result = SendMms(slotId, mmsc, mmsData, ua, uaprof);
509     if (!reply.WriteInt32(result)) {
510         TELEPHONY_LOGE("SmsInterfaceStub::OnSendMms write reply failed");
511         return;
512     }
513 }
514 
OnDownloadMms(MessageParcel & data,MessageParcel & reply,MessageOption & option)515 void SmsInterfaceStub::OnDownloadMms(MessageParcel &data, MessageParcel &reply, MessageOption &option)
516 {
517     int32_t slotId = data.ReadInt32();
518     u16string mmsc = data.ReadString16();
519     u16string mmsData = data.ReadString16();
520     u16string ua = data.ReadString16();
521     u16string uaprof = data.ReadString16();
522     int32_t result = DownloadMms(slotId, mmsc, mmsData, ua, uaprof);
523     if (!reply.WriteInt32(result)) {
524         TELEPHONY_LOGE("SmsInterfaceStub::OnDownloadMms write reply failed");
525         return;
526     }
527 }
528 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)529 int SmsInterfaceStub::OnRemoteRequest(
530     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
531 {
532     TELEPHONY_LOGI("SmsInterfaceStub::OnRemoteRequest code:%{public}d", code);
533     std::u16string myDescripter = SmsInterfaceStub::GetDescriptor();
534     std::u16string remoteDescripter = data.ReadInterfaceToken();
535     if (myDescripter != remoteDescripter) {
536         TELEPHONY_LOGE("descriptor checked fail");
537         return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
538     }
539 
540     auto itFunc = memberFuncMap_.find(code);
541     if (itFunc != memberFuncMap_.end()) {
542         auto memberFunc = itFunc->second;
543         if (memberFunc != nullptr) {
544             (this->*memberFunc)(data, reply, option);
545             return TELEPHONY_ERR_SUCCESS;
546         }
547     }
548     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
549 }
550 } // namespace Telephony
551 } // namespace OHOS
552