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 int32_t GetDefaultSmsSimId(int32_t &simId); 68 69 protected: 70 bool OpenCBRange(uint32_t fromMsgId, uint32_t toMsgId); 71 bool CloseCBRange(uint32_t fromMsgId, uint32_t toMsgId); 72 void NotifyHasResponse(); 73 bool IsEmpty() const; 74 std::string RangeListToString(const std::list<gsmCBRangeInfo> &rangeList); 75 76 std::list<int32_t> fairList_; 77 int32_t fairVar_ = -1; 78 int32_t conditonVar_ = 0; 79 bool isSuccess_ = false; 80 int32_t slotId_; 81 82 private: 83 using infoData = struct info { infoinfo84 info(uint32_t fromMsgId, uint32_t toMsgId) 85 { 86 startPos = fromMsgId; 87 endPos = toMsgId; 88 } 89 bool isMerge = false; 90 uint32_t startPos = 0; 91 uint32_t endPos = 0; 92 }; 93 94 bool SendDataToRil(bool enable, std::list<gsmCBRangeInfo> &list); 95 bool ExpandMsgId( 96 uint32_t fromMsgId, uint32_t toMsgId, const std::list<gsmCBRangeInfo>::iterator &oldIter, infoData &data); 97 void SplitMsgId( 98 uint32_t fromMsgId, uint32_t toMsgId, const std::list<gsmCBRangeInfo>::iterator &oldIter, infoData &data); 99 100 std::list<gsmCBRangeInfo> rangeList_; 101 std::condition_variable condVar_; 102 std::mutex mutex_; 103 std::string smscAddr_; 104 std::string codeScheme_ {"0-255"}; 105 std::list<gsmCBRangeInfo> oldRangeList_; 106 int32_t smsCapacityOfSim_ = 0; 107 }; 108 } // namespace Telephony 109 } // namespace OHOS 110 #endif