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 SMS_RECEIVE_HANDLER_H 17 #define SMS_RECEIVE_HANDLER_H 18 19 #include <memory> 20 #include <unordered_map> 21 #include <vector> 22 23 #include "event_handler.h" 24 #include "event_runner.h" 25 26 #include "hril_sms_parcel.h" 27 #include "sms_base_message.h" 28 #include "sms_common.h" 29 #include "sms_receive_indexer.h" 30 #include "sms_persist_helper.h" 31 #include "sms_wap_push_handler.h" 32 33 namespace OHOS { 34 namespace Telephony { 35 class SmsReceiveHandler : public AppExecFwk::EventHandler { 36 public: 37 SmsReceiveHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner, int32_t slotId); 38 virtual ~SmsReceiveHandler(); 39 virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 40 41 protected: 42 virtual int32_t HandleSmsByType(const std::shared_ptr<SmsBaseMessage> &smsBaseMessage) = 0; 43 virtual void ReplySmsToSmsc(int result, const std::shared_ptr<SmsBaseMessage> &response) = 0; 44 virtual std::shared_ptr<SmsBaseMessage> TransformMessageInfo(const std::shared_ptr<SmsMessageInfo> &info) = 0; 45 void CombineMessagePart(const std::shared_ptr<SmsReceiveIndexer> &smsIndexer); 46 void DeleteMessageFormDb(const std::shared_ptr<SmsReceiveIndexer> &smsIndexer); 47 bool IsRepeatedMessagePart(const std::shared_ptr<SmsReceiveIndexer> &smsIndexer); 48 bool AddMsgToDB(const std::shared_ptr<SmsReceiveIndexer> &indexer); 49 bool CheckBlockPhone(const std::shared_ptr<SmsReceiveIndexer> &indexer); 50 bool CheckSmsCapable(); 51 int32_t slotId_ = -1; 52 53 private: 54 constexpr static uint16_t PDU_POS_OFFSET = 1; 55 constexpr static int32_t TEXT_MSG_RECEIVE_CODE = 0; 56 constexpr static int32_t DATA_MSG_RECEIVE_CODE = 1; 57 58 void SendBroadcast( 59 const std::shared_ptr<SmsReceiveIndexer> &indexer, const std::shared_ptr<std::vector<std::string>> &pdus); 60 void HandleReceivedSms(const std::shared_ptr<SmsBaseMessage> &smsBaseMessage); 61 SmsReceiveHandler(const SmsReceiveHandler &) = delete; 62 SmsReceiveHandler(const SmsReceiveHandler &&) = delete; 63 SmsReceiveHandler &operator=(const SmsReceiveHandler &) = delete; 64 SmsReceiveHandler &operator=(const SmsReceiveHandler &&) = delete; 65 66 std::unique_ptr<SmsWapPushHandler> smsWapPushHandler_; 67 }; 68 } // namespace Telephony 69 } // namespace OHOS 70 #endif