• 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_MISC_MANAGER_H
17 #define SMS_MISC_MANAGER_H
18 
19 #include <condition_variable>
20 #include <list>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 
25 #include "tel_ril_sms_parcel.h"
26 #include "i_sms_service_interface.h"
27 #include "tel_event_handler.h"
28 
29 namespace OHOS {
30 namespace Telephony {
31 class SmsMiscManager : public TelEventHandler {
32 public:
33     enum {
34         SET_CB_CONFIG_FINISH = 0,
35         GET_CB_CONFIG_FINISH,
36         SET_SMSC_ADDR_FINISH,
37         GET_SMSC_ADDR_FINISH,
38     };
39     using gsmCBRangeInfo = struct RangeInfo {
RangeInfoRangeInfo40         RangeInfo(uint32_t fromId, uint32_t toId)
41         {
42             fromMsgId = fromId;
43             toMsgId = toId;
44         }
45         uint32_t fromMsgId = 0;
46         uint32_t toMsgId = 0;
47         bool operator<(const RangeInfo &other) const
48         {
49             return fromMsgId < other.fromMsgId || (fromMsgId == other.fromMsgId && toMsgId < other.toMsgId);
50         }
51         bool operator==(const RangeInfo &other) const
52         {
53             return fromMsgId == other.fromMsgId && toMsgId == other.toMsgId;
54         }
55     };
56     explicit SmsMiscManager(int32_t slotId);
~SmsMiscManager()57     virtual ~SmsMiscManager() {};
58     int32_t SetCBConfig(bool enable, uint32_t fromMsgId, uint32_t toMsgId, uint8_t netType);
59     std::list<gsmCBRangeInfo> GetRangeInfo() const;
60     virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
61     int32_t AddSimMessage(
62         const std::string &smsc, const std::string &pdu, ISmsServiceInterface::SimMessageStatus status);
63     int32_t DelSimMessage(uint32_t msgIndex);
64     int32_t UpdateSimMessage(uint32_t msgIndex, ISmsServiceInterface::SimMessageStatus newStatus,
65         const std::string &pdu, const std::string &smsc);
66     int32_t GetAllSimMessages(std::vector<ShortMessage> &message);
67     int32_t SetSmscAddr(const std::string &scAddr);
68     int32_t GetSmscAddr(std::u16string &smscAddress);
69     int32_t SetDefaultSmsSlotId(int32_t slotId);
70     int32_t GetDefaultSmsSlotId();
71     int32_t GetDefaultSmsSimId(int32_t &simId);
72     int32_t SetCBConfigList(const std::vector<int32_t>& messageIds, int32_t ranType);
73 
74 private:
75     using infoData = struct info {
infoinfo76         info(uint32_t fromMsgId, uint32_t toMsgId)
77         {
78             startPos = fromMsgId;
79             endPos = toMsgId;
80         }
81         bool isMerge = false;
82         uint32_t startPos = 0;
83         uint32_t endPos = 0;
84     };
85 
86 private:
87     bool OpenCBRange(uint32_t fromMsgId, uint32_t toMsgId);
88     bool CloseCBRange(uint32_t fromMsgId, uint32_t toMsgId);
89     void NotifyHasResponse();
90     bool IsEmpty() const;
91     std::string RangeListToString(const std::list<gsmCBRangeInfo> rangeList);
92     bool SendDataToRil(bool enable, std::list<gsmCBRangeInfo> list);
93     void SplitMsgId(uint32_t fromMsgId, uint32_t toMsgId, const std::list<gsmCBRangeInfo>::iterator &oldIter);
94     void UpdateCbRangList(std::shared_ptr<CBConfigInfo> res);
95     void SplitMids(std::string src, std::vector<std::string> &dest, const std::string delimiter);
96     bool SplitMidValue(std::string value, std::string &start, std::string &end, const std::string delimiter);
97     void GetModemCBRange();
98     void CombineCBRange();
99     void CombineCBRange(std::list<gsmCBRangeInfo>& ranges);
100     void GetCBConfigFinish(const AppExecFwk::InnerEvent::Pointer &event);
101     std::list<gsmCBRangeInfo> ConvertToRangeList(const std::vector<int32_t>& messageIds);
102 
103 private:
104     std::list<int32_t> fairList_;
105     int32_t fairVar_ = -1;
106     int32_t conditonVar_ = 0;
107     bool isSuccess_ = false;
108     int32_t slotId_;
109     std::list<gsmCBRangeInfo> rangeList_;
110     std::condition_variable condVar_;
111     std::mutex mutex_;
112     std::mutex cbMutex_;
113     std::string smscAddr_;
114     std::string codeScheme_ { "0-255" };
115     std::list<gsmCBRangeInfo> mdRangeList_;
116     int32_t smsCapacityOfSim_ = 0;
117     static bool hasGotCbRange_;
118 };
119 } // namespace Telephony
120 } // namespace OHOS
121 #endif