• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "sms_service_proxy.h"
17 
18 #include "parcel.h"
19 #include "sms_mms_errors.h"
20 #include "string_utils.h"
21 #include "telephony_errors.h"
22 #include "telephony_log_wrapper.h"
23 
24 namespace OHOS {
25 namespace Telephony {
26 const int32_t MAX_LEN = 10000;
SmsServiceProxy(const sptr<IRemoteObject> & impl)27 SmsServiceProxy::SmsServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<ISmsServiceInterface>(impl) {}
28 
SendMessage(int32_t slotId,const std::u16string desAddr,const std::u16string scAddr,const std::u16string text,const sptr<ISendShortMessageCallback> & sendCallback,const sptr<IDeliveryShortMessageCallback> & deliverCallback)29 int32_t SmsServiceProxy::SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
30     const std::u16string text, const sptr<ISendShortMessageCallback> &sendCallback,
31     const sptr<IDeliveryShortMessageCallback> &deliverCallback)
32 {
33     TELEPHONY_LOGI("SmsServiceProxy::SendMessage with text slotId : %{public}d", slotId);
34     MessageParcel dataParcel;
35     MessageParcel replyParcel;
36     MessageOption option(MessageOption::TF_ASYNC);
37     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
38         TELEPHONY_LOGE("SendMessage with text WriteInterfaceToken is false");
39         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
40     }
41 
42     dataParcel.WriteInt32(slotId);
43     dataParcel.WriteString16(desAddr);
44     dataParcel.WriteString16(scAddr);
45     dataParcel.WriteString16(text);
46     if (sendCallback == nullptr) {
47         TELEPHONY_LOGE("SendMessage with text sendCallback is nullptr");
48         return TELEPHONY_ERR_LOCAL_PTR_NULL;
49     }
50     dataParcel.WriteRemoteObject(sendCallback->AsObject().GetRefPtr());
51     if (deliverCallback == nullptr) {
52         TELEPHONY_LOGE("SendMessage with text deliverCallback is nullptr");
53         return TELEPHONY_ERR_LOCAL_PTR_NULL;
54     }
55     dataParcel.WriteRemoteObject(deliverCallback->AsObject().GetRefPtr());
56 
57     sptr<IRemoteObject> remote = Remote();
58     if (remote == nullptr) {
59         TELEPHONY_LOGE("SendMessage with text Remote is null");
60         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
61     }
62     remote->SendRequest(TEXT_BASED_SMS_DELIVERY, dataParcel, replyParcel, option);
63     return replyParcel.ReadInt32();
64 };
65 
SendMessage(int32_t slotId,const std::u16string desAddr,const std::u16string scAddr,uint16_t port,const uint8_t * data,uint16_t dataLen,const sptr<ISendShortMessageCallback> & sendCallback,const sptr<IDeliveryShortMessageCallback> & deliverCallback)66 int32_t SmsServiceProxy::SendMessage(int32_t slotId, const std::u16string desAddr, const std::u16string scAddr,
67     uint16_t port, const uint8_t *data, uint16_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback,
68     const sptr<IDeliveryShortMessageCallback> &deliverCallback)
69 {
70     TELEPHONY_LOGI("SmsServiceProxy::SendMessage with data slotId : %{public}d", slotId);
71     MessageParcel dataParcel;
72     MessageParcel replyParcel;
73     MessageOption option(MessageOption::TF_ASYNC);
74     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
75         TELEPHONY_LOGE("SendMessage with data WriteInterfaceToken is false");
76         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
77     }
78 
79     dataParcel.WriteInt32(slotId);
80     dataParcel.WriteString16(desAddr);
81     dataParcel.WriteString16(scAddr);
82     dataParcel.WriteInt16(port);
83     if (sendCallback == nullptr) {
84         TELEPHONY_LOGE("SendMessage with data sendCallback is nullptr");
85         return TELEPHONY_ERR_LOCAL_PTR_NULL;
86     }
87     dataParcel.WriteRemoteObject(sendCallback->AsObject().GetRefPtr());
88     if (deliverCallback == nullptr) {
89         TELEPHONY_LOGE("SendMessage with data deliverCallback is nullptr");
90         return TELEPHONY_ERR_LOCAL_PTR_NULL;
91     }
92     dataParcel.WriteRemoteObject(deliverCallback->AsObject().GetRefPtr());
93     dataParcel.WriteInt16(dataLen);
94     dataParcel.WriteRawData(data, dataLen);
95 
96     sptr<IRemoteObject> remote = Remote();
97     if (remote == nullptr) {
98         TELEPHONY_LOGE("SendMessage with data Remote is null");
99         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
100     }
101     remote->SendRequest(DATA_BASED_SMS_DELIVERY, dataParcel, replyParcel, option);
102     return replyParcel.ReadInt32();
103 };
104 
SetSmscAddr(int32_t slotId,const std::u16string & scAddr)105 int32_t SmsServiceProxy::SetSmscAddr(int32_t slotId, const std::u16string &scAddr)
106 {
107     TELEPHONY_LOGI("SmsServiceProxy::SetSmscAddr slotId : %{public}d", slotId);
108     MessageParcel dataParcel;
109     MessageParcel replyParcel;
110     MessageOption option(MessageOption::TF_SYNC);
111     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
112         TELEPHONY_LOGE("SetSmscAddr WriteInterfaceToken is false");
113         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
114     }
115     dataParcel.WriteInt32(slotId);
116     dataParcel.WriteString16(scAddr);
117     sptr<IRemoteObject> remote = Remote();
118     if (remote == nullptr) {
119         TELEPHONY_LOGE("SetSmscAddr Remote is null");
120         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
121     }
122     remote->SendRequest(SET_SMSC_ADDRESS, dataParcel, replyParcel, option);
123     return replyParcel.ReadInt32();
124 }
125 
GetSmscAddr(int32_t slotId,std::u16string & smscAddress)126 int32_t SmsServiceProxy::GetSmscAddr(int32_t slotId, std::u16string &smscAddress)
127 {
128     TELEPHONY_LOGI("SmsServiceProxy::GetSmscAddr slotId : %{public}d", slotId);
129     MessageParcel dataParcel;
130     MessageParcel replyParcel;
131     MessageOption option(MessageOption::TF_SYNC);
132     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
133         TELEPHONY_LOGE("GetSmscAddr WriteInterfaceToken is false");
134         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
135     }
136     dataParcel.WriteInt32(slotId);
137     sptr<IRemoteObject> remote = Remote();
138     if (remote == nullptr) {
139         TELEPHONY_LOGE("GetSmscAddr Remote is null");
140         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
141     }
142     remote->SendRequest(GET_SMSC_ADDRESS, dataParcel, replyParcel, option);
143     int32_t result = replyParcel.ReadInt32();
144     if (result == TELEPHONY_ERR_SUCCESS) {
145         smscAddress = replyParcel.ReadString16();
146     }
147     return result;
148 }
149 
AddSimMessage(int32_t slotId,const std::u16string & smsc,const std::u16string & pdu,SimMessageStatus status)150 int32_t SmsServiceProxy::AddSimMessage(
151     int32_t slotId, const std::u16string &smsc, const std::u16string &pdu, SimMessageStatus status)
152 {
153     TELEPHONY_LOGI("SmsServiceProxy::AddSimMessage slotId : %{public}d", slotId);
154     MessageParcel dataParcel;
155     MessageParcel replyParcel;
156     MessageOption option(MessageOption::TF_SYNC);
157     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
158         TELEPHONY_LOGE("AddSimMessage WriteInterfaceToken is false");
159         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
160     }
161     dataParcel.WriteInt32(slotId);
162     dataParcel.WriteString16(smsc);
163     dataParcel.WriteString16(pdu);
164     dataParcel.WriteUint32(status);
165     sptr<IRemoteObject> remote = Remote();
166     if (remote == nullptr) {
167         TELEPHONY_LOGE("AddSimMessage Remote is null");
168         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
169     }
170     remote->SendRequest(ADD_SIM_MESSAGE, dataParcel, replyParcel, option);
171     return replyParcel.ReadInt32();
172 }
173 
DelSimMessage(int32_t slotId,uint32_t msgIndex)174 int32_t SmsServiceProxy::DelSimMessage(int32_t slotId, uint32_t msgIndex)
175 {
176     TELEPHONY_LOGI("SmsServiceProxy::DelSimMessage slotId : %{public}d", slotId);
177     MessageParcel dataParcel;
178     MessageParcel replyParcel;
179     MessageOption option(MessageOption::TF_SYNC);
180     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
181         TELEPHONY_LOGE("DelSimMessage WriteInterfaceToken is false");
182         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
183     }
184     dataParcel.WriteInt32(slotId);
185     dataParcel.WriteUint32(msgIndex);
186     sptr<IRemoteObject> remote = Remote();
187     if (remote == nullptr) {
188         TELEPHONY_LOGE("DelSimMessage Remote is null");
189         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
190     }
191     remote->SendRequest(DEL_SIM_MESSAGE, dataParcel, replyParcel, option);
192     return replyParcel.ReadInt32();
193 }
194 
UpdateSimMessage(int32_t slotId,uint32_t msgIndex,SimMessageStatus newStatus,const std::u16string & pdu,const std::u16string & smsc)195 int32_t SmsServiceProxy::UpdateSimMessage(int32_t slotId, uint32_t msgIndex, SimMessageStatus newStatus,
196     const std::u16string &pdu, const std::u16string &smsc)
197 {
198     TELEPHONY_LOGI("SmsServiceProxy::UpdateSimMessage slotId : %{public}d", slotId);
199     MessageParcel dataParcel;
200     MessageParcel replyParcel;
201     MessageOption option(MessageOption::TF_SYNC);
202     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
203         TELEPHONY_LOGE("UpdateSimMessage WriteInterfaceToken is false");
204         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
205     }
206     dataParcel.WriteInt32(slotId);
207     dataParcel.WriteUint32(msgIndex);
208     dataParcel.WriteUint32(newStatus);
209     dataParcel.WriteString16(pdu);
210     dataParcel.WriteString16(smsc);
211     sptr<IRemoteObject> remote = Remote();
212     if (remote == nullptr) {
213         TELEPHONY_LOGE("UpdateSimMessage Remote is null");
214         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
215     }
216     remote->SendRequest(UPDATE_SIM_MESSAGE, dataParcel, replyParcel, option);
217     return replyParcel.ReadInt32();
218 }
219 
GetAllSimMessages(int32_t slotId,std::vector<ShortMessage> & message)220 int32_t SmsServiceProxy::GetAllSimMessages(int32_t slotId, std::vector<ShortMessage> &message)
221 {
222     TELEPHONY_LOGI("SmsServiceProxy::GetAllSimMessages slotId : %{public}d", slotId);
223     MessageParcel dataParcel;
224     MessageParcel replyParcel;
225     MessageOption option(MessageOption::TF_SYNC);
226     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
227         TELEPHONY_LOGE("GetAllSimMessages WriteInterfaceToken is false");
228         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
229     }
230     dataParcel.WriteInt32(slotId);
231     sptr<IRemoteObject> remote = Remote();
232     if (remote == nullptr) {
233         TELEPHONY_LOGE("GetAllSimMessages Remote is null");
234         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
235     }
236     remote->SendRequest(GET_ALL_SIM_MESSAGE, dataParcel, replyParcel, option);
237     int32_t result = replyParcel.ReadInt32();
238     if (result != TELEPHONY_ERR_SUCCESS) {
239         TELEPHONY_LOGE("GetAllSimMessages result is not TELEPHONY_ERR_SUCCESS");
240         return result;
241     }
242     int32_t resultLen = replyParcel.ReadInt32();
243     if (resultLen >= MAX_LEN) {
244         TELEPHONY_LOGE("GetAllSimMessages resultLen over max");
245         return SMS_MMS_MESSAGE_LENGTH_OUT_OF_RANGE;
246     }
247     for (int32_t i = 0; i < resultLen; i++) {
248         message.emplace_back(ShortMessage::UnMarshalling(replyParcel));
249     }
250     return result;
251 }
252 
SetCBConfig(int32_t slotId,bool enable,uint32_t fromMsgId,uint32_t toMsgId,uint8_t netType)253 int32_t SmsServiceProxy::SetCBConfig(
254     int32_t slotId, bool enable, uint32_t fromMsgId, uint32_t toMsgId, uint8_t netType)
255 {
256     TELEPHONY_LOGI("SmsServiceProxy::SetCBConfig slotId : %{public}d", slotId);
257     MessageParcel dataParcel;
258     MessageParcel replyParcel;
259     MessageOption option(MessageOption::TF_SYNC);
260     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
261         TELEPHONY_LOGE("SetCBConfig WriteInterfaceToken is false");
262         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
263     }
264     dataParcel.WriteInt32(slotId);
265     dataParcel.WriteBool(enable);
266     dataParcel.WriteUint32(fromMsgId);
267     dataParcel.WriteUint32(toMsgId);
268     dataParcel.WriteUint8(netType);
269     sptr<IRemoteObject> remote = Remote();
270     if (remote == nullptr) {
271         TELEPHONY_LOGE("SetCBConfig Remote is null");
272         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
273     }
274     remote->SendRequest(SET_CB_CONFIG, dataParcel, replyParcel, option);
275     return replyParcel.ReadInt32();
276 }
277 
SetImsSmsConfig(int32_t slotId,int32_t enable)278 bool SmsServiceProxy::SetImsSmsConfig(
279     int32_t slotId, int32_t enable)
280 {
281     TELEPHONY_LOGI("SmsServiceProxy::SetImsSmsConfig slotId : %{public}d", slotId);
282     bool result = false;
283     MessageParcel dataParcel;
284     MessageParcel replyParcel;
285     MessageOption option(MessageOption::TF_SYNC);
286     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
287         TELEPHONY_LOGE("SetImsSmsConfig WriteInterfaceToken is false");
288         return result;
289     }
290     dataParcel.WriteInt32(slotId);
291     dataParcel.WriteInt32(enable);
292     sptr<IRemoteObject> remote = Remote();
293     if (remote == nullptr) {
294         TELEPHONY_LOGE("SetImsSmsConfig Remote is null");
295         return result;
296     }
297     remote->SendRequest(SET_IMS_SMS_CONFIG, dataParcel, replyParcel, option);
298     return replyParcel.ReadBool();
299 }
300 
SetDefaultSmsSlotId(int32_t slotId)301 int32_t SmsServiceProxy::SetDefaultSmsSlotId(int32_t slotId)
302 {
303     TELEPHONY_LOGI("SmsServiceProxy::SetDefaultSmsSlotId slotId : %{public}d", slotId);
304     MessageParcel dataParcel;
305     MessageParcel replyParcel;
306     MessageOption option(MessageOption::TF_SYNC);
307     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
308         TELEPHONY_LOGE("SetDefaultSmsSlotId WriteInterfaceToken is false");
309         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
310     }
311     dataParcel.WriteInt32(slotId);
312     sptr<IRemoteObject> remote = Remote();
313     if (remote == nullptr) {
314         TELEPHONY_LOGE("SetDefaultSmsSlotId Remote is null");
315         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
316     }
317     remote->SendRequest(SET_DEFAULT_SMS_SLOT_ID, dataParcel, replyParcel, option);
318     return replyParcel.ReadInt32();
319 }
320 
GetDefaultSmsSlotId()321 int32_t SmsServiceProxy::GetDefaultSmsSlotId()
322 {
323     TELEPHONY_LOGI("SmsServiceProxy::GetDefaultSmsSlotId");
324     int32_t result = -1;
325     MessageParcel dataParcel;
326     MessageParcel replyParcel;
327     MessageOption option(MessageOption::TF_SYNC);
328     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
329         TELEPHONY_LOGE("GetDefaultSmsSlotId WriteInterfaceToken is false");
330         return result;
331     }
332     sptr<IRemoteObject> remote = Remote();
333     if (remote == nullptr) {
334         TELEPHONY_LOGE("GetDefaultSmsSlotId Remote is null");
335         return result;
336     }
337     remote->SendRequest(GET_DEFAULT_SMS_SLOT_ID, dataParcel, replyParcel, option);
338     return replyParcel.ReadInt32();
339 }
340 
SplitMessage(const std::u16string & message,std::vector<std::u16string> & splitMessage)341 int32_t SmsServiceProxy::SplitMessage(const std::u16string &message, std::vector<std::u16string> &splitMessage)
342 {
343     TELEPHONY_LOGI("SmsServiceProxy::SplitMessage");
344     MessageParcel dataParcel;
345     MessageParcel replyParcel;
346     MessageOption option(MessageOption::TF_SYNC);
347     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
348         TELEPHONY_LOGE("SplitMessage WriteInterfaceToken is false");
349         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
350     }
351     dataParcel.WriteString16(message);
352     sptr<IRemoteObject> remote = Remote();
353     if (remote == nullptr) {
354         TELEPHONY_LOGE("SplitMessage Remote is null");
355         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
356     }
357     remote->SendRequest(SPLIT_MESSAGE, dataParcel, replyParcel, option);
358     int32_t result = replyParcel.ReadInt32();
359     if (result != TELEPHONY_ERR_SUCCESS) {
360         TELEPHONY_LOGE("SplitMessage result is not TELEPHONY_ERR_SUCCESS");
361         return result;
362     }
363     int32_t resultLen = replyParcel.ReadInt32();
364     if (resultLen >= MAX_LEN) {
365         TELEPHONY_LOGE("SplitMessage resultLen over max");
366         return SMS_MMS_MESSAGE_LENGTH_OUT_OF_RANGE;
367     }
368     for (int32_t i = 0; i < resultLen; ++i) {
369         splitMessage.emplace_back(replyParcel.ReadString16());
370     }
371     return result;
372 }
373 
GetSmsSegmentsInfo(int32_t slotId,const std::u16string & message,bool force7BitCode,ISmsServiceInterface::SmsSegmentsInfo & segInfo)374 int32_t SmsServiceProxy::GetSmsSegmentsInfo(
375     int32_t slotId, const std::u16string &message, bool force7BitCode, ISmsServiceInterface::SmsSegmentsInfo &segInfo)
376 {
377     TELEPHONY_LOGI("SmsServiceProxy::GetSmsSegmentsInfo slotId : %{public}d", slotId);
378     MessageParcel dataParcel;
379     MessageParcel replyParcel;
380     MessageOption option(MessageOption::TF_SYNC);
381     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
382         TELEPHONY_LOGE("GetSmsSegmentsInfo WriteInterfaceToken is false");
383         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
384     }
385     dataParcel.WriteInt32(slotId);
386     dataParcel.WriteString16(message);
387     dataParcel.WriteBool(force7BitCode);
388     sptr<IRemoteObject> remote = Remote();
389     if (remote == nullptr) {
390         TELEPHONY_LOGE("GetSmsSegmentsInfo Remote is null");
391         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
392     }
393     remote->SendRequest(GET_SMS_SEGMENTS_INFO, dataParcel, replyParcel, option);
394     int32_t result = replyParcel.ReadInt32();
395     if (result != TELEPHONY_ERR_SUCCESS) {
396         TELEPHONY_LOGE("GetSmsSegmentsInfo ReadInt32 is null");
397         return result;
398     }
399 
400     segInfo.msgSegCount = replyParcel.ReadInt32();
401     segInfo.msgEncodingCount = replyParcel.ReadInt32();
402     segInfo.msgRemainCount = replyParcel.ReadInt32();
403     int32_t cds = replyParcel.ReadInt32();
404     segInfo.msgCodeScheme = static_cast<ISmsServiceInterface::SmsSegmentsInfo::SmsSegmentCodeScheme>(cds);
405     return TELEPHONY_ERR_SUCCESS;
406 }
407 
IsImsSmsSupported(int32_t slotId,bool & isSupported)408 int32_t SmsServiceProxy::IsImsSmsSupported(int32_t slotId, bool &isSupported)
409 {
410     TELEPHONY_LOGI("SmsServiceProxy::IsImsSmsSupported slotId : %{public}d", slotId);
411     MessageParcel dataParcel;
412     MessageParcel replyParcel;
413     MessageOption option(MessageOption::TF_SYNC);
414     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
415         TELEPHONY_LOGE("IsImsSmsSupported WriteInterfaceToken is false");
416         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
417     }
418     dataParcel.WriteInt32(slotId);
419     sptr<IRemoteObject> remote = Remote();
420     if (remote == nullptr) {
421         TELEPHONY_LOGE("IsImsSmsSupported Remote is null");
422         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
423     }
424     remote->SendRequest(IS_IMS_SMS_SUPPORTED, dataParcel, replyParcel, option);
425     int32_t result = replyParcel.ReadInt32();
426     if (result != TELEPHONY_ERR_SUCCESS) {
427         TELEPHONY_LOGE("IsImsSmsSupported result:%{public}d", result);
428         return result;
429     }
430     isSupported = replyParcel.ReadBool();
431     return result;
432 }
433 
GetImsShortMessageFormat(std::u16string & format)434 int32_t SmsServiceProxy::GetImsShortMessageFormat(std::u16string &format)
435 {
436     TELEPHONY_LOGI("SmsServiceProxy::GetImsShortMessageFormat");
437     MessageParcel dataParcel;
438     MessageParcel replyParcel;
439     MessageOption option(MessageOption::TF_SYNC);
440     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
441         TELEPHONY_LOGE("GetImsShortMessageFormat WriteInterfaceToken is false");
442         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
443     }
444     sptr<IRemoteObject> remote = Remote();
445     if (remote == nullptr) {
446         TELEPHONY_LOGE("GetImsShortMessageFormat Remote is null");
447         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
448     }
449     remote->SendRequest(GET_IMS_SHORT_MESSAGE_FORMAT, dataParcel, replyParcel, option);
450     int32_t result = replyParcel.ReadInt32();
451     if (result == TELEPHONY_ERR_SUCCESS) {
452         format = replyParcel.ReadString16();
453     }
454     return result;
455 }
456 
HasSmsCapability()457 bool SmsServiceProxy::HasSmsCapability()
458 {
459     TELEPHONY_LOGI("SmsServiceProxy::HasSmsCapability");
460     bool result = false;
461     MessageParcel dataParcel;
462     MessageParcel replyParcel;
463     MessageOption option(MessageOption::TF_SYNC);
464     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
465         TELEPHONY_LOGE("HasSmsCapability WriteInterfaceToken is false");
466         return result;
467     }
468     sptr<IRemoteObject> remote = Remote();
469     if (remote == nullptr) {
470         TELEPHONY_LOGE("HasSmsCapability Remote is null");
471         return result;
472     }
473     remote->SendRequest(HAS_SMS_CAPABILITY, dataParcel, replyParcel, option);
474     return replyParcel.ReadBool();
475 }
476 
CreateMessage(std::string pdu,std::string specification,ShortMessage & message)477 int32_t SmsServiceProxy::CreateMessage(std::string pdu, std::string specification, ShortMessage &message)
478 {
479     if (pdu.empty() || specification.empty()) {
480         return TELEPHONY_ERR_ARGUMENT_INVALID;
481     }
482 
483     MessageParcel dataParcel;
484     MessageParcel replyParcel;
485     MessageOption option(MessageOption::TF_SYNC);
486     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
487         TELEPHONY_LOGE("CreateMessage WriteInterfaceToken is false");
488         return TELEPHONY_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
489     }
490 
491     dataParcel.WriteString(pdu);
492     dataParcel.WriteString(specification);
493 
494     sptr<IRemoteObject> remote = Remote();
495     if (remote == nullptr) {
496         return TELEPHONY_ERR_IPC_CONNECT_STUB_FAIL;
497     }
498     remote->SendRequest(CREATE_MESSAGE, dataParcel, replyParcel, option);
499 
500     int32_t result = replyParcel.ReadInt32();
501     TELEPHONY_LOGI("SmsServiceProxy::CreateMessage result:%{public}d", result);
502     if (result != TELEPHONY_ERR_SUCCESS) {
503         TELEPHONY_LOGE("CreateMessage result fail");
504         return result;
505     }
506 
507     if (!message.ReadFromParcel(replyParcel)) {
508         TELEPHONY_LOGE("SmsServiceProxy::CreateMessage fail");
509         return TELEPHONY_ERR_LOCAL_PTR_NULL;
510     }
511     return result;
512 }
513 
GetBase64Encode(std::string src,std::string & dest)514 bool SmsServiceProxy::GetBase64Encode(std::string src, std::string &dest)
515 {
516     bool result = false;
517     if (src.empty()) {
518         return result;
519     }
520 
521     MessageParcel dataParcel;
522     MessageParcel replyParcel;
523     MessageOption option(MessageOption::TF_SYNC);
524     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
525         TELEPHONY_LOGE("GetBase64Encode WriteInterfaceToken is false");
526         return result;
527     }
528 
529     dataParcel.WriteString16(StringUtils::ToUtf16(src));
530 
531     sptr<IRemoteObject> remote = Remote();
532     if (remote == nullptr) {
533         return result;
534     }
535     remote->SendRequest(MMS_BASE64_ENCODE, dataParcel, replyParcel, option);
536 
537     result = replyParcel.ReadBool();
538     TELEPHONY_LOGI("SmsServiceProxy::GetBase64Encode result:%{public}d", result);
539     if (!result) {
540         return result;
541     }
542     dest = StringUtils::ToUtf8(dataParcel.ReadString16());
543     return result;
544 }
545 
GetBase64Decode(std::string src,std::string & dest)546 bool SmsServiceProxy::GetBase64Decode(std::string src, std::string &dest)
547 {
548     bool result = false;
549     if (src.empty()) {
550         return result;
551     }
552 
553     MessageParcel dataParcel;
554     MessageParcel replyParcel;
555     MessageOption option(MessageOption::TF_SYNC);
556     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
557         TELEPHONY_LOGE("GetBase64Decode WriteInterfaceToken is false");
558         return result;
559     }
560 
561     dataParcel.WriteString16(StringUtils::ToUtf16(src));
562 
563     sptr<IRemoteObject> remote = Remote();
564     if (remote == nullptr) {
565         return result;
566     }
567     remote->SendRequest(MMS_BASE64_DECODE, dataParcel, replyParcel, option);
568     result = replyParcel.ReadBool();
569     TELEPHONY_LOGI("SmsServiceProxy::GetBase64Decode result:%{public}d", result);
570     if (!result) {
571         return result;
572     }
573     dest = StringUtils::ToUtf8(dataParcel.ReadString16());
574     return result;
575 }
576 
GetEncodeStringFunc(std::string & encodeString,uint32_t charset,uint32_t valLength,std::string strEncodeString)577 bool SmsServiceProxy::GetEncodeStringFunc(
578     std::string &encodeString, uint32_t charset, uint32_t valLength, std::string strEncodeString)
579 {
580     bool result = false;
581     if (strEncodeString.empty()) {
582         return result;
583     }
584 
585     MessageParcel dataParcel;
586     MessageParcel replyParcel;
587     MessageOption option(MessageOption::TF_SYNC);
588     if (!dataParcel.WriteInterfaceToken(SmsServiceProxy::GetDescriptor())) {
589         TELEPHONY_LOGE("GetEncodeStringFunc WriteInterfaceToken is false");
590         return result;
591     }
592 
593     dataParcel.WriteUint32(charset);
594     dataParcel.WriteUint32(valLength);
595     dataParcel.WriteString16(StringUtils::ToUtf16(strEncodeString));
596 
597     sptr<IRemoteObject> remote = Remote();
598     if (remote == nullptr) {
599         return result;
600     }
601     remote->SendRequest(GET_ENCODE_STRING, dataParcel, replyParcel, option);
602     result = replyParcel.ReadBool();
603     TELEPHONY_LOGI("SmsServiceProxy::GetEncodeStringFunc result:%{public}d", result);
604     if (!result) {
605         return result;
606     }
607     encodeString = StringUtils::ToUtf8(dataParcel.ReadString16());
608     return result;
609 }
610 
611 bool SmsServiceDeathRecipient::gotDeathRecipient_ = false;
612 
GotDeathRecipient()613 bool SmsServiceDeathRecipient::GotDeathRecipient()
614 {
615     return gotDeathRecipient_;
616 }
617 
OnRemoteDied(const wptr<IRemoteObject> & remote)618 void SmsServiceDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
619 {
620     gotDeathRecipient_ = true;
621 }
622 
SmsServiceDeathRecipient()623 SmsServiceDeathRecipient::SmsServiceDeathRecipient() {}
624 
~SmsServiceDeathRecipient()625 SmsServiceDeathRecipient::~SmsServiceDeathRecipient() {}
626 } // namespace Telephony
627 } // namespace OHOS
628