/* * Copyright (C) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SMS_SENDER_H #define SMS_SENDER_H #include #include #include #include #include #include #include #include "event_handler.h" #include "event_runner.h" #include "hril_sms_parcel.h" #include "i_sms_service_interface.h" #include "sms_send_indexer.h" #include "sms_persist_helper.h" #include "network_state.h" namespace OHOS { namespace Telephony { class SmsSender : public AppExecFwk::EventHandler { public: virtual ~SmsSender(); SmsSender(const std::shared_ptr &runner, int32_t slotId, std::function)> &sendRetryFun); virtual void TextBasedSmsDelivery(const std::string &desAddr, const std::string &scAddr, const std::string &text, const sptr &sendCallback, const sptr &deliveryCallback) = 0; virtual void DataBasedSmsDelivery(const std::string &desAddr, const std::string &scAddr, int32_t port, const uint8_t *data, uint32_t dataLen, const sptr &sendCallback, const sptr &deliveryCallback) = 0; virtual void SendSmsToRil(const std::shared_ptr &smsIndexer) = 0; void HandleMessageResponse(const std::shared_ptr &smsIndexer); virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; virtual void Init() = 0; virtual void ResendTextDelivery(const std::shared_ptr &smsIndexer) = 0; virtual void ResendDataDelivery(const std::shared_ptr &smsIndexer) = 0; static void SendResultCallBack( const std::shared_ptr &indexer, ISendShortMessageCallback::SmsSendResult result); static void SendResultCallBack( const sptr &sendCallback, ISendShortMessageCallback::SmsSendResult result); void SetNetworkState(bool isImsNetDomain, int32_t voiceServiceState); std::optional GetNetworkId(); void SetNetworkId(std::optional &id); protected: void SendCacheMapTimeoutCheck(); bool SendCacheMapLimitCheck(const sptr &sendCallback); bool SendCacheMapAddItem(int64_t id, const std::shared_ptr &smsIndexer); bool SendCacheMapEraseItem(int64_t id); std::shared_ptr FindCacheMapAndTransform(const AppExecFwk::InnerEvent::Pointer &event); uint8_t GetMsgRef8Bit(); int64_t GetMsgRef64Bit(); virtual void StatusReportAnalysis(const AppExecFwk::InnerEvent::Pointer &event) = 0; void SendMessageSucceed(const std::shared_ptr &smsIndexer); void SendMessageFailed(const std::shared_ptr &smsIndexer); bool CheckForce7BitEncodeType(); int32_t slotId_ = -1; std::list> reportList_; bool isImsNetDomain_ = false; int32_t voiceServiceState_ = static_cast(RegServiceState::REG_STATE_UNKNOWN); private: static constexpr uint16_t EXPIRED_TIME = 60 * 3; static constexpr uint16_t DELAY_MAX_TIME_MSCE = 2000; static constexpr uint8_t MSG_QUEUE_LIMIT = 25; static constexpr uint8_t MAX_REPORT_LIST_LIMIT = 25; static constexpr uint8_t MAX_SEND_RETRIES = 3; SmsSender(const SmsSender &) = delete; SmsSender(const SmsSender &&) = delete; SmsSender &operator=(const SmsSender &) = delete; SmsSender &operator=(const SmsSender &&) = delete; void HandleResend(const std::shared_ptr &smsIndexer); std::function)> sendRetryFun_; std::unordered_map> sendCacheMap_; std::mutex sendCacheMapMutex_; uint8_t msgRef8bit_ = 0; int64_t msgRef64bit_ = 0; std::optional networkId_ = std::nullopt; }; } // namespace Telephony } // namespace OHOS #endif