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