• 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 #ifndef GSM_SMS_SENDER_H
17 #define GSM_SMS_SENDER_H
18 
19 #include <functional>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 
24 #include "event_runner.h"
25 #include "gsm_sms_message.h"
26 #include "i_delivery_short_message_callback.h"
27 #include "i_send_short_message_callback.h"
28 #include "ims_sms_client.h"
29 #include "sms_send_indexer.h"
30 #include "sms_sender.h"
31 #include "telephony_types.h"
32 
33 namespace OHOS {
34 namespace Telephony {
35 class GsmSmsSender : public SmsSender {
36 public:
37     GsmSmsSender(const std::shared_ptr<AppExecFwk::EventRunner> &runner, int32_t slotId,
38         const std::function<void(std::shared_ptr<SmsSendIndexer>)> sendRetryFun);
39     ~GsmSmsSender() override;
40     void Init() override;
41     void TextBasedSmsDelivery(const std::string &desAddr, const std::string &scAddr, const std::string &text,
42         const sptr<ISendShortMessageCallback> &sendCallback,
43         const sptr<IDeliveryShortMessageCallback> &deliveryCallback) override;
44     void DataBasedSmsDelivery(const std::string &desAddr, const std::string &scAddr, int32_t port,
45         const uint8_t *data, uint32_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback,
46         const sptr<IDeliveryShortMessageCallback> &deliveryCallback) override;
47     void DataBasedSmsDeliverySplitPage(GsmSmsMessage &gsmSmsMessage, std::vector<struct SplitInfo> cellsInfos,
48         std::shared_ptr<struct SmsTpdu> tpdu, uint8_t msgRef8bit, const std::string &desAddr, const std::string &scAddr,
49         int32_t port, const sptr<ISendShortMessageCallback> &sendCallback,
50         const sptr<IDeliveryShortMessageCallback> &deliveryCallback);
51     void DataBasedSmsDeliveryPacketSplitPage(GsmSmsMessage &gsmSmsMessage, std::shared_ptr<struct SmsTpdu> tpdu,
52         uint8_t msgRef8bit, uint32_t indexData, int32_t port, const std::string &scAddr,
53         const sptr<ISendShortMessageCallback> &sendCallback,
54         const sptr<IDeliveryShortMessageCallback> &deliveryCallback, std::shared_ptr<SmsSendIndexer> indexer,
55         std::vector<struct SplitInfo> cellsInfos);
56     void DataBasedSmsDeliverySendSplitPage(std::shared_ptr<struct EncodeInfo> encodeInfo,
57         const sptr<ISendShortMessageCallback> &sendCallback, std::shared_ptr<SmsSendIndexer> indexer,
58         uint8_t msgRef8bit, uint32_t totalPage);
59     void CharArrayToString(const uint8_t *data, uint32_t dataLen, std::string &dataStr);
60     void SendCallbackBecauseTpduNull(const sptr<ISendShortMessageCallback> &sendCallback, std::string str);
61     void SendSmsToRil(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
62     void ResendTextDelivery(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
63     void ResendDataDelivery(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
64     int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported) override;
65     void StatusReportSetImsSms(const AppExecFwk::InnerEvent::Pointer &event) override;
66     void StatusReportGetImsSms(const AppExecFwk::InnerEvent::Pointer &event) override;
67     void RegisterImsHandler() override;
68 
69 protected:
70     void StatusReportAnalysis(const AppExecFwk::InnerEvent::Pointer &event) override;
71 
72 private:
73     void SetSendIndexerInfo(const std::shared_ptr<SmsSendIndexer> &indexer,
74         const std::shared_ptr<struct EncodeInfo> &encodeInfo, unsigned char msgRef8bit);
75     bool RegisterHandler();
76     bool SetPduInfo(const std::shared_ptr<SmsSendIndexer> &smsIndexer, GsmSmsMessage &gsmSmsMessage, bool &isMore);
77     void SendImsSms(const std::shared_ptr<SmsSendIndexer> &smsIndexer, GsmSimMessageParam smsData);
78     void SendCsSms(const std::shared_ptr<SmsSendIndexer> &smsIndexer, GsmSimMessageParam smsData);
79 
80 private:
81     std::mutex mutex_;
82     bool isImsGsmHandlerRegistered = false;
83 };
84 } // namespace Telephony
85 } // namespace OHOS
86 #endif