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