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_USIM_DIALLING_NUMBERS_SERVICE_H 17 #define OHOS_USIM_DIALLING_NUMBERS_SERVICE_H 18 19 #include "icc_file_controller.h" 20 #include "sim_constant.h" 21 #include "icc_dialling_numbers_handler.h" 22 #include "tag_service.h" 23 #include "telephony_log_wrapper.h" 24 #include "sim_utils.h" 25 26 namespace OHOS { 27 namespace Telephony { 28 enum UsimMessage { 29 MSG_USIM_PBR_LOAD_DONE = 1, 30 MSG_USIM_USIM_ADN_LOAD_DONE = 2 31 }; 32 33 struct UsimDiallingNumberFile { 34 std::map<int, std::shared_ptr<TagData>> fileIds_ {}; 35 int fileNumber_ = 0; 36 }; 37 38 enum UsimConstant { 39 LEN_MIN = 2, 40 LEN_MAX = 3, 41 INVALID_SFI = -1, 42 BIT_OF_BYTE = 8 43 }; 44 45 class UsimDiallingNumbersService : public AppExecFwk::EventHandler { 46 public: 47 explicit UsimDiallingNumbersService(const std::shared_ptr<AppExecFwk::EventRunner> &runner); 48 ~UsimDiallingNumbersService(); 49 void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event); 50 void ObtainUsimElementaryFiles(const AppExecFwk::InnerEvent::Pointer &pointer); 51 void EnableReloadFiles(); 52 void SetFileControllerAndDiallingNumberHandler( 53 std::shared_ptr<IccFileController> &ctrl, std::shared_ptr<IccDiallingNumbersHandler> handler); 54 55 protected: 56 std::shared_ptr<IccFileController> fileController_ = nullptr; 57 bool pbrFileLoaded_ = true; 58 std::vector<std::shared_ptr<UsimDiallingNumberFile>> pbrFiles_; 59 std::vector<std::shared_ptr<DiallingNumbersInfo>> diallingNumbersFiles_; 60 std::map<int, int> efIdOfSfi_; 61 uint pbrIndex_ = 0; 62 void ReloadAllFiles(); 63 void LoadPbrFiles(); 64 std::shared_ptr<IccDiallingNumbersHandler> diallingNumbersHandler_ = nullptr; 65 AppExecFwk::InnerEvent::Pointer callerPointer_ = AppExecFwk::InnerEvent::Pointer(nullptr, nullptr); 66 67 private: 68 using ProcessFunc = void (UsimDiallingNumbersService::*)(const AppExecFwk::InnerEvent::Pointer &event); 69 std::map<int, ProcessFunc> memberFuncMap_; 70 void UpdatePhoneDiallingNumberFile(); 71 std::string GetEmailContents(int index); 72 bool LoadDiallingNumberFiles(int index); 73 void GeneratePbrFile(std::vector<std::string> &records); 74 AppExecFwk::InnerEvent::Pointer BuildCallerInfo(int eventId); 75 AppExecFwk::InnerEvent::Pointer CreateHandlerPointer( 76 int eventid, int efId, int index, std::shared_ptr<void> pobj); 77 static std::mutex mtx_; 78 void ProcessPbrLoadDone(const AppExecFwk::InnerEvent::Pointer &event); 79 void ProcessDiallingNumberLoadDone(const AppExecFwk::InnerEvent::Pointer &event); 80 void FillDiallingNumbersRecords(const std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>> &list); 81 bool CheckEmailFiles(const std::shared_ptr<TagData> &email, int index); 82 83 std::shared_ptr<UsimDiallingNumberFile> BuildNumberFileByRecord(const std::string &record); 84 void StorePbrDetailInfo(std::shared_ptr<UsimDiallingNumberFile> file, 85 std::shared_ptr<TagService> tlv, int parentTag); 86 void SendBackResult(const std::shared_ptr<std::vector<std::shared_ptr<DiallingNumbersInfo>>> &diallingnumbers); 87 void SendLocalBack(); 88 void InitFuncMap(); 89 void NextStep(int msgId); 90 const int NEXT = 123; 91 enum UsimFileType { 92 TYPE1_FLAG = 168, // 3gpp 31102-9j0 4.4.2.1 93 TYPE2_FLAG = 169, 94 TYPE3_FLAG = 170, 95 TAG_SIM_USIM_ADN = 192, 96 TAG_SIM_USIM_IAP, 97 TAG_SIM_USIM_EXT1, 98 TAG_SIM_USIM_SNE, 99 TAG_SIM_USIM_ANR, // 3gpp 31102-9j0 4.4.2.9 100 TAG_SIM_USIM_PBC, 101 TAG_SIM_USIM_GRP, 102 TAG_SIM_USIM_AAS, 103 TAG_SIM_USIM_GSD, 104 TAG_SIM_USIM_UID, 105 TAG_SIM_USIM_EMAIL, 106 TAG_SIM_USIM_CCP1 107 }; 108 }; 109 } // namespace Telephony 110 } // namespace OHOS 111 #endif // OHOS_USIM_DIALLING_NUMBERS_SERVICE_H