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_CB_HANDLER_H 17 #define GSM_SMS_CB_HANDLER_H 18 19 #include <map> 20 #include <memory> 21 22 #include "common_event.h" 23 #include "common_event_manager.h" 24 #include "want.h" 25 26 #include "event_handler.h" 27 #include "event_runner.h" 28 #include "hril_sms_parcel.h" 29 #include "sms_cb_data.h" 30 #include "sms_cb_message.h" 31 32 enum SmsCbType { SMS_CB_TYPE = 0, SMS_ETWS_TYPE }; 33 34 namespace OHOS { 35 namespace Telephony { 36 using SmsCbInfo = struct CbInfo { CbInfoCbInfo37 CbInfo(const std::shared_ptr<SmsCbMessage::SmsCbMessageHeader> &headPtr, 38 const std::map<unsigned char, std::shared_ptr<SmsCbMessage>> &cbPtr) 39 : header(headPtr), cbMsgs(cbPtr) 40 {} CbInfoCbInfo41 CbInfo() {} 42 std::shared_ptr<SmsCbMessage::SmsCbMessageHeader> header; 43 std::map<unsigned char, std::shared_ptr<SmsCbMessage>> cbMsgs; 44 std::u16string plmn_; 45 int32_t lac_ = -1; 46 int32_t cid_ = -1; 47 MatchLocationCbInfo48 bool MatchLocation(std::u16string plmn, int32_t lac, int32_t cid) 49 { 50 const int32_t defaultValue = -1; 51 if (plmn != plmn_) { 52 return false; 53 } 54 if (lac_ != defaultValue && lac_ != lac) { 55 return false; 56 } 57 if (cid_ != defaultValue && cid_ != cid) { 58 return false; 59 } 60 return true; 61 } 62 }; 63 64 class GsmSmsCbHandler : public AppExecFwk::EventHandler { 65 public: 66 GsmSmsCbHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner, int32_t slotId); 67 ~GsmSmsCbHandler() = default; 68 void Init(); 69 void UnRegisterHandler(); 70 virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; 71 72 static constexpr uint16_t MAX_CB_MSG_TEXT_LEN = 4200; 73 static constexpr uint8_t MAX_CB_MSG_LANGUAGE_TYPE_LEN = 3; 74 static constexpr uint8_t MAX_ETWS_WARNING_DATA_INFO_LEN = 50; 75 76 private: 77 bool CheckCbActive(const std::shared_ptr<SmsCbMessage> &cbMessage); 78 unsigned char CheckCbMessage(const std::shared_ptr<SmsCbMessage> &cbMessage); 79 std::unique_ptr<SmsCbInfo> FindCbMessage(const std::shared_ptr<SmsCbMessage> &cbMessage); 80 bool AddCbMessageToList(const std::shared_ptr<SmsCbMessage> &cbMessage); 81 bool RemoveCbMessageFromList(const std::shared_ptr<SmsCbMessage> &cbMessage); 82 bool SendCbMessageBroadcast(const std::shared_ptr<SmsCbMessage> &cbMessage); 83 void HandleCbMessage(std::shared_ptr<CBConfigReportInfo> &message); 84 bool SetWantData(EventFwk::Want &want, const std::shared_ptr<SmsCbMessage> &cbMessage); 85 bool InitLocation(SmsCbInfo &info); 86 void GetCbData(const std::shared_ptr<SmsCbMessage> &cbMessage, 87 SmsCbData::CbData &SendData); 88 89 int32_t slotId_; 90 std::vector<SmsCbInfo> cbMsgList_; 91 int32_t cid_ = -1; 92 int32_t lac_ = -1; 93 std::u16string plmn_; 94 }; 95 } // namespace Telephony 96 } // namespace OHOS 97 #endif