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 <mutex>
21 
22 #include "gsm_sms_message.h"
23 #include "i_delivery_short_message_callback.h"
24 #include "i_send_short_message_callback.h"
25 #include "ims_sms_client.h"
26 #include "satellite_sms_callback.h"
27 #include "sms_sender.h"
28 #include "telephony_types.h"
29 
30 namespace OHOS {
31 namespace Telephony {
32 class GsmSmsSender : public SmsSender {
33 public:
34     GsmSmsSender(int32_t slotId, const std::function<void(std::shared_ptr<SmsSendIndexer>)> sendRetryFun);
35     ~GsmSmsSender() override;
36     void Init() override;
37     void TextBasedSmsDelivery(const std::string &desAddr, const std::string &scAddr, const std::string &text,
38         const sptr<ISendShortMessageCallback> &sendCallback,
39         const sptr<IDeliveryShortMessageCallback> &deliveryCallback) override;
40     void DataBasedSmsDelivery(const std::string &desAddr, const std::string &scAddr, int32_t port, const uint8_t *data,
41         uint32_t dataLen, const sptr<ISendShortMessageCallback> &sendCallback,
42         const sptr<IDeliveryShortMessageCallback> &deliveryCallback) override;
43     void SendSmsToRil(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
44     void ResendTextDelivery(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
45     void ResendDataDelivery(const std::shared_ptr<SmsSendIndexer> &smsIndexer) override;
46     int32_t IsImsSmsSupported(int32_t slotId, bool &isSupported) override;
47     void StatusReportSetImsSms(const AppExecFwk::InnerEvent::Pointer &event) override;
48     void StatusReportGetImsSms(const AppExecFwk::InnerEvent::Pointer &event) override;
49     void RegisterImsHandler() override;
50     void RegisterSatelliteCallback();
51     void UnregisterSatelliteCallback();
52 
53 protected:
54     void StatusReportAnalysis(const AppExecFwk::InnerEvent::Pointer &event) override;
55 
56 private:
57     void SetSendIndexerInfo(const std::shared_ptr<SmsSendIndexer> &indexer,
58         const std::shared_ptr<struct EncodeInfo> &encodeInfo, unsigned char msgRef8bit);
59     bool RegisterHandler();
60     bool SetPduInfo(const std::shared_ptr<SmsSendIndexer> &smsIndexer, GsmSmsMessage &gsmSmsMessage, bool &isMore);
61     void SendImsSms(const std::shared_ptr<SmsSendIndexer> &smsIndexer, GsmSimMessageParam smsData);
62     void SendCsSms(const std::shared_ptr<SmsSendIndexer> &smsIndexer, GsmSimMessageParam smsData);
63     void SendSatelliteSms(const std::shared_ptr<SmsSendIndexer> &smsIndexer, GsmSimMessageParam smsData);
64     void OnSatelliteStateChange(bool satelliteSwitch);
65     void TextBasedSmsSplitDelivery(const std::string &desAddr, const std::string &scAddr,
66         std::vector<struct SplitInfo> cellsInfos, DataCodingScheme codingType, bool isStatusReport,
67         std::shared_ptr<struct SmsTpdu> tpdu, GsmSmsMessage &gsmSmsMessage,
68         const sptr<ISendShortMessageCallback> &sendCallback,
69         const sptr<IDeliveryShortMessageCallback> &deliveryCallback);
70 
71 private:
72     std::mutex mutex_;
73     bool isImsGsmHandlerRegistered = false;
74     sptr<ISatelliteSmsCallback> satelliteCallback_ = nullptr;
75 };
76 } // namespace Telephony
77 } // namespace OHOS
78 #endif