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