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