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 OHOS_SIM_DIALLING_NUMBERS_CACHE_H 17 #define OHOS_SIM_DIALLING_NUMBERS_CACHE_H 18 19 #include "sim_file_manager.h" 20 #include "tel_event_handler.h" 21 22 namespace OHOS { 23 namespace Telephony { 24 enum { 25 MSG_SIM_OBTAIN_ADN_DETAILS_DONE, 26 MSG_SIM_CHANGE_DIALLING_NUMBERS_DONE, 27 MSG_SIM_OBTAIN_PBR_DETAILS_DONE, 28 }; 29 30 const int ADD_FLAG = -1; 31 class UsimDiallingNumbersService; 32 class IccDiallingNumbersHandler; 33 class IccDiallingNumbersCache : public TelEventHandler { 34 public: 35 explicit IccDiallingNumbersCache(std::shared_ptr<SimFileManager> simFileManager); 36 ~IccDiallingNumbersCache(); 37 void Init(); 38 std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>> LoadReadyDiallingNumbers(int fileId); 39 int ExtendedElementFile(int fileId); 40 void UpdateDiallingNumberToIcc(int fileId, std::shared_ptr<DiallingNumbersInfo> diallingNumberInfor, 41 int recordIndex, bool isDel, const AppExecFwk::InnerEvent::Pointer &caller); 42 void ObtainAllDiallingNumberFiles(int fileId, int extensionEf, const AppExecFwk::InnerEvent::Pointer &caller); 43 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); 44 void ClearDiallingNumberCache(); 45 46 protected: 47 std::shared_ptr<SimFileManager> simFileManager_ = nullptr; 48 std::shared_ptr<IccDiallingNumbersHandler> diallingNumbersHandler_ = nullptr; 49 std::shared_ptr<UsimDiallingNumbersService> usimDiallingNumberSrv_ = nullptr; 50 std::map<int, std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>>> diallingNumberFileList_; 51 std::map<int, int> extTypeMap_; 52 void SendUpdateResult(const AppExecFwk::InnerEvent::Pointer &caller, const std::shared_ptr<void> &object); 53 void SendBackResult(const AppExecFwk::InnerEvent::Pointer &caller, 54 const std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>> &ar, 55 const std::shared_ptr<void> &object); 56 57 private: 58 void SendExceptionResult(const AppExecFwk::InnerEvent::Pointer &caller, int errCode); 59 AppExecFwk::InnerEvent::Pointer BuildCallerInfo( 60 int eventId, int fileId, int index, std::shared_ptr<void> pobj, const AppExecFwk::InnerEvent::Pointer &caller); 61 AppExecFwk::InnerEvent::Pointer CreateUsimPointer( 62 int eventId, int fileId, const AppExecFwk::InnerEvent::Pointer &caller); 63 void ProcessObtainAdnDetailsDone(const AppExecFwk::InnerEvent::Pointer &event); 64 void ProcessChangeDiallingNumbersDone(const AppExecFwk::InnerEvent::Pointer &event); 65 void ProcessObtainPbrDetailsDone(const AppExecFwk::InnerEvent::Pointer &event); 66 bool IsDiallingNumberEqual( 67 const std::shared_ptr<DiallingNumbersInfo> &src, const std::shared_ptr<DiallingNumbersInfo> &dest); 68 bool StringEqual(const std::u16string &s1, const std::u16string &s2); 69 bool ArrayEqual(const std::vector<std::u16string> &mailsSrc, const std::vector<std::u16string> &mailsDest); 70 bool CheckValueAndOperation(const std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>> &list, 71 const std::shared_ptr<DiallingNumbersInfo> &info, int &index, int fileId); 72 void SearchIndexByNameAndNumber(const std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>> &list, 73 const std::shared_ptr<DiallingNumbersInfo> &info, int &index); 74 void InitFileTypeMap(); 75 }; 76 } // namespace Telephony 77 } // namespace OHOS 78 #endif // OHOS_SIM_DIALLING_NUMBERS_CACHE_H