• 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 <vector>
20 #include <list>
21 #include <mutex>
22 #include <string>
23 #include <condition_variable>
24 
25 #include "event_handler.h"
26 #include "event_runner.h"
27 
28 #include "i_sms_service_interface.h"
29 
30 namespace OHOS {
31 namespace Telephony {
32 class SmsMiscManager : public AppExecFwk::EventHandler {
33 public:
34     enum {
35         SET_CB_CONFIG_FINISH = 0,
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;
50         }
51     };
52     SmsMiscManager(const std::shared_ptr<AppExecFwk::EventRunner> &runner, int32_t slotId);
~SmsMiscManager()53     virtual ~SmsMiscManager() {};
54     int32_t SetCBConfig(bool enable, uint32_t fromMsgId, uint32_t toMsgId, uint8_t netType);
55     std::list<gsmCBRangeInfo> GetRangeInfo() const;
56     virtual void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override;
57     int32_t AddSimMessage(
58         const std::string &smsc, const std::string &pdu, ISmsServiceInterface::SimMessageStatus status);
59     int32_t DelSimMessage(uint32_t msgIndex);
60     int32_t UpdateSimMessage(uint32_t msgIndex, ISmsServiceInterface::SimMessageStatus newStatus,
61         const std::string &pdu, const std::string &smsc);
62     int32_t GetAllSimMessages(std::vector<ShortMessage> &message);
63     int32_t SetSmscAddr(const std::string &scAddr);
64     int32_t GetSmscAddr(std::u16string &smscAddress);
65     int32_t SetDefaultSmsSlotId(int32_t slotId);
66     int32_t GetDefaultSmsSlotId();
67 
68 protected:
69     bool OpenCBRange(uint32_t fromMsgId, uint32_t toMsgId);
70     bool CloseCBRange(uint32_t fromMsgId, uint32_t toMsgId);
71     void NotifyHasResponse();
72     bool IsEmpty() const;
73     std::string RangeListToString(const std::list<gsmCBRangeInfo> &rangeList);
74 
75     std::list<int32_t> fairList_;
76     int32_t fairVar_ = -1;
77     int32_t conditonVar_ = 0;
78     bool isSuccess_ = false;
79     int32_t slotId_;
80 
81 private:
82     using infoData = struct info {
infoinfo83         info(uint32_t fromMsgId, uint32_t toMsgId)
84         {
85             startPos = fromMsgId;
86             endPos = toMsgId;
87         }
88         bool isMerge = false;
89         uint32_t startPos;
90         uint32_t endPos;
91     };
92 
93     bool SendDataToRil(bool enable, std::list<gsmCBRangeInfo> &list);
94     bool ExpandMsgId(
95         uint32_t fromMsgId, uint32_t toMsgId, const std::list<gsmCBRangeInfo>::iterator &oldIter, infoData &data);
96     void SplitMsgId(
97         uint32_t fromMsgId, uint32_t toMsgId, const std::list<gsmCBRangeInfo>::iterator &oldIter, infoData &data);
98 
99     std::list<gsmCBRangeInfo> rangeList_;
100     std::condition_variable condVar_;
101     std::mutex mutex_;
102     std::string smscAddr_;
103     std::string codeScheme_ {"0-255"};
104     std::list<gsmCBRangeInfo> oldRangeList_;
105 };
106 } // namespace Telephony
107 } // namespace OHOS
108 #endif