• 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 #include "isim_file.h"
17 
18 #include "radio_event.h"
19 #include "common_event_manager.h"
20 #include "common_event_support.h"
21 
22 using namespace std;
23 using namespace OHOS::AppExecFwk;
24 using namespace OHOS::EventFwk;
25 
26 namespace OHOS {
27 namespace Telephony {
IsimFile(std::shared_ptr<SimStateManager> simStateManager)28 IsimFile::IsimFile(std::shared_ptr<SimStateManager> simStateManager) : IccFile("IsimFile", simStateManager)
29 {
30     fileQueried_ = false;
31     InitMemberFunc();
32 }
33 
StartLoad()34 void IsimFile::StartLoad()
35 {
36     TELEPHONY_LOGI("IsimFile::StartLoad() start");
37     LoadIsimFiles();
38 }
39 
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)40 void IsimFile::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
41 {
42     if (event == nullptr) {
43         TELEPHONY_LOGE("event is nullptr!");
44         return;
45     }
46     auto id = event->GetInnerEventId();
47     bool isFileHandleResponse = false;
48     TELEPHONY_LOGD("IsimFile::ProcessEvent id %{public}d", id);
49     auto itFunc = memberFuncMap_.find(id);
50     if (itFunc != memberFuncMap_.end()) {
51         auto memberFunc = itFunc->second;
52         if (memberFunc != nullptr) {
53             isFileHandleResponse = (this->*memberFunc)(event);
54         }
55     } else {
56         IccFile::ProcessEvent(event);
57     }
58     ProcessFileLoaded(isFileHandleResponse);
59 }
60 
ProcessIccRefresh(int msgId)61 void IsimFile::ProcessIccRefresh(int msgId)
62 {
63     LoadIsimFiles();
64 }
65 
ProcessFileLoaded(bool response)66 void IsimFile::ProcessFileLoaded(bool response)
67 {
68     if (!response) {
69         return;
70     }
71     fileToGet_ -= LOAD_STEP;
72     TELEPHONY_LOGI("IsimFile::ProcessFileLoaded: %{public}d requested: %{public}d", fileToGet_, fileQueried_);
73     if (ObtainFilesFetched()) {
74         OnAllFilesFetched();
75     } else if (LockQueriedOrNot()) {
76         ProcessLockedAllFilesFetched();
77     } else if (fileToGet_ < 0) {
78         fileToGet_ = 0;
79     }
80 }
81 
ProcessLockedAllFilesFetched()82 void IsimFile::ProcessLockedAllFilesFetched() {}
83 
OnAllFilesFetched()84 void IsimFile::OnAllFilesFetched()
85 {
86     filesFetchedObser_->NotifyObserver(RadioEvent::RADIO_SIM_RECORDS_LOADED, slotId_);
87     NotifyRegistrySimState(CardType::SINGLE_MODE_ISIM_CARD, SimState::SIM_STATE_LOADED, LockReason::SIM_NONE);
88     LoadVoiceMail();
89 }
90 
ProcessIccReady(const AppExecFwk::InnerEvent::Pointer & event)91 bool IsimFile::ProcessIccReady(const AppExecFwk::InnerEvent::Pointer &event)
92 {
93     TELEPHONY_LOGI("IsimFile::SIM_STATE_READY --received");
94     if (stateManager_ == nullptr) {
95         TELEPHONY_LOGE("stateManager_ is nullptr!");
96         return false;
97     }
98     if (stateManager_->GetCardType() != CardType::SINGLE_MODE_ISIM_CARD) {
99         TELEPHONY_LOGI("invalid IsimFile::SIM_STATE_READY received");
100         return false;
101     }
102     LoadIsimFiles();
103     return false;
104 }
105 
ProcessIsimRefresh(const AppExecFwk::InnerEvent::Pointer & event)106 bool IsimFile::ProcessIsimRefresh(const AppExecFwk::InnerEvent::Pointer &event)
107 {
108     return false;
109 }
110 
LoadIsimFiles()111 void IsimFile::LoadIsimFiles()
112 {
113     TELEPHONY_LOGI("LoadIsimFiles started");
114     fileQueried_ = true;
115     AppExecFwk::InnerEvent::Pointer eventImpi = BuildCallerInfo(MSG_SIM_OBTAIN_IMPI_DONE);
116     fileController_->ObtainBinaryFile(ELEMENTARY_FILE_IMPI, eventImpi);
117     fileToGet_++;
118 
119     AppExecFwk::InnerEvent::Pointer eventIst = BuildCallerInfo(MSG_SIM_OBTAIN_IST_DONE);
120     fileController_->ObtainBinaryFile(ELEMENTARY_FILE_IST, eventIst);
121     fileToGet_++;
122 }
123 
124 
ProcessGetIccidDone(const AppExecFwk::InnerEvent::Pointer & event)125 bool IsimFile::ProcessGetIccidDone(const AppExecFwk::InnerEvent::Pointer &event)
126 {
127     bool isFileProcessResponse = true;
128     if (event == nullptr) {
129         TELEPHONY_LOGE("event is nullptr!");
130         return isFileProcessResponse;
131     }
132     std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
133     if (fd == nullptr) {
134         TELEPHONY_LOGE("fd is nullptr!");
135         return isFileProcessResponse;
136     }
137     if (fd->exception == nullptr) {
138         std::string iccData = fd->resultData;
139         TELEPHONY_LOGI("IsimFile::ProcessEvent MSG_SIM_OBTAIN_ICCID_DONE result success");
140         iccId_ = iccData;
141     }
142     return isFileProcessResponse;
143 }
144 
ProcessGetImsiDone(const AppExecFwk::InnerEvent::Pointer & event)145 bool IsimFile::ProcessGetImsiDone(const AppExecFwk::InnerEvent::Pointer &event)
146 {
147     bool isFileHandleResponse = true;
148     if (event == nullptr) {
149         TELEPHONY_LOGE("event is nullptr!");
150         return isFileHandleResponse;
151     }
152     std::shared_ptr<std::string> sharedObject = event->GetSharedObject<std::string>();
153     if (sharedObject == nullptr) {
154         TELEPHONY_LOGE("fd is nullptr!");
155         return isFileHandleResponse;
156     }
157     if (sharedObject != nullptr) {
158         imsi_ = *sharedObject;
159         TELEPHONY_LOGI("IsimFile::ProcessEvent MSG_SIM_OBTAIN_IMSI_DONE");
160         SaveCountryCode();
161         if (!imsi_.empty()) {
162             imsiReadyObser_->NotifyObserver(RadioEvent::RADIO_IMSI_LOADED_READY);
163         }
164     }
165     return isFileHandleResponse;
166 }
167 
InitMemberFunc()168 void IsimFile::InitMemberFunc()
169 {
170     memberFuncMap_[RadioEvent::RADIO_SIM_STATE_READY] = &IsimFile::ProcessIccReady;
171     memberFuncMap_[MSG_ICC_REFRESH] = &IsimFile::ProcessIsimRefresh;
172     memberFuncMap_[MSG_SIM_OBTAIN_IMSI_DONE] = &IsimFile::ProcessGetImsiDone;
173     memberFuncMap_[MSG_SIM_OBTAIN_ICCID_DONE] = &IsimFile::ProcessGetIccidDone;
174     memberFuncMap_[MSG_SIM_OBTAIN_IMPI_DONE] = &IsimFile::ProcessGetImpiDone;
175     memberFuncMap_[MSG_SIM_OBTAIN_IST_DONE] = &IsimFile::ProcessGetIstDone;
176 }
177 
ProcessGetImpiDone(const AppExecFwk::InnerEvent::Pointer & event)178 bool IsimFile::ProcessGetImpiDone(const AppExecFwk::InnerEvent::Pointer &event)
179 {
180     bool isFileProcessResponse = true;
181     if (event == nullptr) {
182         TELEPHONY_LOGE("event is nullptr!");
183         return isFileProcessResponse;
184     }
185     std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
186     if (fd == nullptr) {
187         TELEPHONY_LOGE("fd is nullptr!");
188         return isFileProcessResponse;
189     }
190     if (fd->exception != nullptr) {
191         TELEPHONY_LOGE("ProcessGetImpiDone get exception");
192         return isFileProcessResponse;
193     }
194     imsi_ = fd->resultData;
195     TELEPHONY_LOGI("IsimFile::ProcessGetImpiDone success");
196     return isFileProcessResponse;
197 }
198 
ProcessGetIstDone(const AppExecFwk::InnerEvent::Pointer & event)199 bool IsimFile::ProcessGetIstDone(const AppExecFwk::InnerEvent::Pointer &event)
200 {
201     bool isFileProcessResponse = true;
202     if (event == nullptr) {
203         TELEPHONY_LOGE("event is nullptr!");
204         return isFileProcessResponse;
205     }
206     std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
207     if (fd == nullptr) {
208         TELEPHONY_LOGE("fd is nullptr!");
209         return isFileProcessResponse;
210     }
211     if (fd->exception != nullptr) {
212         TELEPHONY_LOGE("ProcessGetIstDone get exception");
213         return isFileProcessResponse;
214     }
215     ist_ = fd->resultData;
216     TELEPHONY_LOGI("IsimFile::ProcessGetIstDone success");
217     return isFileProcessResponse;
218 }
219 
ObtainIsimImpi()220 std::string IsimFile::ObtainIsimImpi()
221 {
222     return impi_;
223 }
ObtainIsimDomain()224 std::string IsimFile::ObtainIsimDomain()
225 {
226     return domain_;
227 }
ObtainIsimImpu()228 std::string* IsimFile::ObtainIsimImpu()
229 {
230     return impu_;
231 }
ObtainIsimIst()232 std::string IsimFile::ObtainIsimIst()
233 {
234     return ist_;
235 }
ObtainIsimPcscf()236 std::string* IsimFile::ObtainIsimPcscf()
237 {
238     return pcscf_;
239 }
240 
UpdateVoiceMail(const std::string & mailName,const std::string & mailNumber)241 bool IsimFile::UpdateVoiceMail(const std::string &mailName, const std::string &mailNumber)
242 {
243     // cdma not support
244     return false;
245 }
246 
SetVoiceMailCount(int32_t voiceMailCount)247 bool IsimFile::SetVoiceMailCount(int32_t voiceMailCount)
248 {
249     // cdma not support
250     return false;
251 }
252 
SetVoiceCallForwarding(bool enable,const std::string & number)253 bool IsimFile::SetVoiceCallForwarding(bool enable, const std::string &number)
254 {
255     // cdma not support
256     return false;
257 }
258 
ObtainSpnCondition(bool roaming,const std::string & operatorNum)259 int IsimFile::ObtainSpnCondition(bool roaming, const std::string &operatorNum)
260 {
261     return 0;
262 }
263 
ObtainIsoCountryCode()264 std::string IsimFile::ObtainIsoCountryCode()
265 {
266     return "";
267 }
268 
GetVoiceMailNumber()269 std::string IsimFile::GetVoiceMailNumber()
270 {
271     std::shared_lock<std::shared_mutex> lock(voiceMailMutex_);
272     return voiceMailNum_;
273 }
274 
SetVoiceMailNumber(const std::string mailNumber)275 void IsimFile::SetVoiceMailNumber(const std::string mailNumber)
276 {
277     std::unique_lock<std::shared_mutex> lock(voiceMailMutex_);
278     voiceMailNum_ = mailNumber;
279 }
280 
~IsimFile()281 IsimFile::~IsimFile() {}
282 } // namespace Telephony
283 } // namespace OHOS
284