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 bool 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 bool AddSimMessage( 58 const std::string &smsc, const std::string &pdu, ISmsServiceInterface::SimMessageStatus status); 59 bool DelSimMessage(uint32_t msgIndex); 60 bool UpdateSimMessage(uint32_t msgIndex, ISmsServiceInterface::SimMessageStatus newStatus, 61 const std::string &pdu, const std::string &smsc); 62 std::vector<ShortMessage> GetAllSimMessages(); 63 bool SetSmscAddr(const std::string &scAddr); 64 std::string GetSmscAddr(); 65 bool 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 static constexpr uint8_t GSM_TYPE = 1; 83 static constexpr uint8_t MIN_SMSC_LEN = 2; 84 static constexpr uint32_t RANG_MAX = 65535; 85 using infoData = struct info { infoinfo86 info(uint32_t fromMsgId, uint32_t toMsgId) 87 { 88 startPos = fromMsgId; 89 endPos = toMsgId; 90 } 91 bool isMerge = false; 92 uint32_t startPos; 93 uint32_t endPos; 94 }; 95 96 bool SendDataToRil(bool enable, std::list<gsmCBRangeInfo> &list); 97 bool ExpandMsgId( 98 uint32_t fromMsgId, uint32_t toMsgId, const std::list<gsmCBRangeInfo>::iterator &oldIter, infoData &data); 99 void SplitMsgId( 100 uint32_t fromMsgId, uint32_t toMsgId, const std::list<gsmCBRangeInfo>::iterator &oldIter, infoData &data); 101 102 std::list<gsmCBRangeInfo> rangeList_; 103 std::condition_variable condVar_; 104 std::mutex mutex_; 105 std::string smscAddr_; 106 std::string codeScheme_ {"0-255"}; 107 std::list<gsmCBRangeInfo> oldRangeList_; 108 }; 109 } // namespace Telephony 110 } // namespace OHOS 111 #endif