• 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 #ifndef CDMA_SMS_SENDER_H
17 #define CDMA_SMS_SENDER_H
18 
19 #include <memory>
20 
21 #include "gsm_sms_message.h"
22 #include "ims_sms_client.h"
23 #include "sms_receive_indexer.h"
24 #include "sms_sender.h"
25 
26 namespace OHOS {
27 namespace Telephony {
28 class CdmaSmsSender : public SmsSender {
29 public:
30     CdmaSmsSender(int32_t slotId, std::function<void(std::shared_ptr<SmsSendIndexer>)> sendRetryFun);
31     ~CdmaSmsSender() override;
32     void TextBasedSmsDelivery(const std::string &desAddr, const std::string &scAddr, const std::string &text,
33         const sptr<ISendShortMessageCallback> &sendCallback,
34         const sptr<IDeliveryShortMessageCallback> &deliveryCallback, uint16_t id, bool isMmsApp = true) override;
35     void TextBasedSmsDeliveryViaIms(const std::string &desAddr, const std::string &scAddr, const std::string &text,
36         const sptr<ISendShortMessageCallback> &sendCallback,
37         const sptr<IDeliveryShortMessageCallback> &deliveryCallback, uint16_t dataBaseId, bool isMmsApp = true);
38     bool TpduNullOrSmsPageOverNormalOrSmsEncodeFail(std::vector<struct SplitInfo> cellsInfos,
39         std::shared_ptr<struct SmsTpdu> tpdu, std::shared_ptr<uint8_t> unSentCellCount,
40         std::shared_ptr<bool> hasCellFailed, const sptr<ISendShortMessageCallback> &sendCallback);
41     void SendSmsForEveryIndexer(int &i, std::vector<struct SplitInfo> cellsInfos, const std::string &desAddr,
42         const std::string &scAddr, std::shared_ptr<struct SmsTpdu> tpdu, GsmSmsMessage gsmSmsMessage,
43         std::shared_ptr<uint8_t> unSentCellCount, std::shared_ptr<bool> hasCellFailed, DataCodingScheme codingType,
44         uint8_t msgRef8bit, const sptr<ISendShortMessageCallback> &sendCallback,
45         const sptr<IDeliveryShortMessageCallback> &deliveryCallback,
46         uint16_t dataBaseId, bool isMmsApp = true);
47     void ReadySendSms(GsmSmsMessage gsmSmsMessage, const std::string &scAddr, bool isMore,
48         std::shared_ptr<SmsSendIndexer> indexer, uint8_t msgRef8bit, std::shared_ptr<uint8_t> unSentCellCount,
49         std::shared_ptr<bool> hasCellFailed);
50     void DataBasedSmsDelivery(const std::string &desAddr, const std::string &scAddr, int32_t port, const uint8_t *data,
51         uint32_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback,
52         const sptr<IDeliveryShortMessageCallback> &deliveryCallback) override;
53     void DataBasedSmsDeliveryViaIms(const std::string &desAddr, const std::string &scAddr, int32_t port,
54         const uint8_t *data, uint32_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback,
55         const sptr<IDeliveryShortMessageCallback> &deliveryCallback);
56     void SendSmsToRil(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
57     void Init() override;
58     void ReceiveStatusReport(const std::shared_ptr<SmsReceiveIndexer> &smsIndexer);
59     void ResendTextDelivery(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
60     void ResendDataDelivery(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
61     int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported) override;
62     void StatusReportSetImsSms(const AppExecFwk::InnerEvent::Pointer &event) override;
63     void StatusReportGetImsSms(const AppExecFwk::InnerEvent::Pointer &event) override;
64     void RegisterImsHandler() override;
65     void UpdateIndexerInfo(std::shared_ptr<SmsSendIndexer> &smsIndexer, uint8_t msgRef8bit,
66         const uint8_t unSentCellCount, std::shared_ptr<bool> hasCellFailed,
67         long timeStamp, uint16_t msgId, uint16_t dataBaseId, bool isMmsApp);
68     void SetSendIndexerInfo(const std::shared_ptr<SmsSendIndexer> &indexer,
69         const std::shared_ptr<struct EncodeInfo> &encodeInfo, unsigned char msgRef8bit);
70 
71 protected:
72     void StatusReportAnalysis(const AppExecFwk::InnerEvent::Pointer &event) override;
73 
74 private:
75     static constexpr uint16_t TAPI_NETTEXT_SMDATA_SIZE_MAX = 255;
76 
77     void SetConcact(
78         const std::shared_ptr<SmsSendIndexer> &smsIndexer, const std::unique_ptr<CdmaTransportMsg> &transMsg);
79     uint8_t GetSeqNum();
80     uint8_t GetSubmitMsgId();
81     void SetPduSeqInfo(const std::shared_ptr<SmsSendIndexer> &smsIndexer, const std::size_t size,
82         const std::unique_ptr<CdmaTransportMsg> &transMsg, const std::size_t index, const uint8_t msgRef8bit);
83 
84     void SendCsSms(const std::shared_ptr<SmsSendIndexer> &smsIndexer, int64_t &refId, std::string &pdu);
85     void SendImsSms(const std::shared_ptr<SmsSendIndexer> &smsIndexer, int64_t &refId, std::string &pdu);
86     void EncodeMsgData(std::unique_ptr<CdmaTransportMsg> transMsg, std::shared_ptr<SmsSendIndexer> indexer,
87         uint8_t msgRef8bit, const sptr<ISendShortMessageCallback> &sendCallback);
88 
89     std::unique_ptr<std::vector<uint8_t>> EncodeMsg(CdmaTransportMsg &msg);
90     void TextBasedSmsSplitDelivery(const std::string &desAddr, const std::string &scAddr,
91         std::vector<struct SplitInfo> splits, std::unique_ptr<CdmaTransportMsg> transMsg, uint8_t msgRef8bit,
92         uint16_t msgId, long timeStamp, const sptr<ISendShortMessageCallback> &sendCallback,
93         const sptr<IDeliveryShortMessageCallback> &deliveryCallback, uint16_t dataBaseId, bool isMmsApp = true);
94 
95 private:
96     uint8_t msgSeqNum_ = 0;
97     uint8_t msgSubmitId_ = 0;
98 
99     std::mutex mutex_;
100     bool isImsCdmaHandlerRegistered = false;
101 };
102 } // namespace Telephony
103 } // namespace OHOS
104 #endif
105