• 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 
20 using namespace std;
21 using namespace OHOS::AppExecFwk;
22 
23 namespace OHOS {
24 namespace Telephony {
IsimFile(const std::shared_ptr<AppExecFwk::EventRunner> & runner,std::shared_ptr<SimStateManager> simStateManager)25 IsimFile::IsimFile(
26     const std::shared_ptr<AppExecFwk::EventRunner> &runner, std::shared_ptr<SimStateManager> simStateManager)
27     : IccFile(runner, simStateManager)
28 {
29     fileQueried_ = false;
30     InitMemberFunc();
31 }
32 
Init()33 void IsimFile::Init()
34 {
35     TELEPHONY_LOGI("IsimFile:::Init():start");
36     IccFile::Init();
37     if (stateManager_ != nullptr) {
38         stateManager_->RegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_STATE_READY);
39         stateManager_->RegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_STATE_LOCKED);
40         stateManager_->RegisterCoreNotify(shared_from_this(), RadioEvent::RADIO_SIM_STATE_SIMLOCK);
41     }
42 }
43 
StartLoad()44 void IsimFile::StartLoad()
45 {
46     TELEPHONY_LOGI("IsimFile::StartLoad() start");
47     LoadIsimFiles();
48 }
49 
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)50 void IsimFile::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
51 {
52     auto id = event->GetInnerEventId();
53     bool isFileHandleResponse = false;
54     TELEPHONY_LOGI("IsimFile::ProcessEvent id %{public}d", id);
55     auto itFunc = memberFuncMap_.find(id);
56     if (itFunc != memberFuncMap_.end()) {
57         auto memberFunc = itFunc->second;
58         if (memberFunc != nullptr) {
59             isFileHandleResponse = (this->*memberFunc)(event);
60         }
61     } else {
62         IccFile::ProcessEvent(event);
63     }
64     ProcessFileLoaded(isFileHandleResponse);
65 }
66 
ProcessIccRefresh(int msgId)67 void IsimFile::ProcessIccRefresh(int msgId)
68 {
69     LoadIsimFiles();
70 }
71 
ProcessFileLoaded(bool response)72 void IsimFile::ProcessFileLoaded(bool response)
73 {
74     if (!response) {
75         return;
76     }
77     fileToGet_ -= LOAD_STEP;
78     TELEPHONY_LOGI("IsimFile::ProcessFileLoaded: %{public}d requested: %{public}d", fileToGet_, fileQueried_);
79     if (ObtainFilesFetched()) {
80         OnAllFilesFetched();
81     } else if (LockQueriedOrNot()) {
82         ProcessLockedAllFilesFetched();
83     } else if (fileToGet_ < 0) {
84         fileToGet_ = 0;
85     }
86 }
87 
ProcessLockedAllFilesFetched()88 void IsimFile::ProcessLockedAllFilesFetched() {}
89 
OnAllFilesFetched()90 void IsimFile::OnAllFilesFetched()
91 {
92     filesFetchedObser_->NotifyObserver(RadioEvent::RADIO_SIM_RECORDS_LOADED, slotId_);
93     PublishSimFileEvent(SIM_STATE_ACTION, ICC_STATE_LOADED, "");
94 }
95 
ProcessIccReady(const AppExecFwk::InnerEvent::Pointer & event)96 bool IsimFile::ProcessIccReady(const AppExecFwk::InnerEvent::Pointer &event)
97 {
98     TELEPHONY_LOGI("IsimFile::SIM_STATE_READY --received");
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 
121 
ProcessGetIccidDone(const AppExecFwk::InnerEvent::Pointer & event)122 bool IsimFile::ProcessGetIccidDone(const AppExecFwk::InnerEvent::Pointer &event)
123 {
124     std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
125     bool isFileProcessResponse = true;
126     if (fd->exception == nullptr) {
127         std::string iccData = fd->resultData;
128         TELEPHONY_LOGI("IsimFile::ProcessEvent MSG_SIM_OBTAIN_ICCID_DONE result success");
129         iccId_ = iccData;
130     }
131     return isFileProcessResponse;
132 }
133 
ProcessGetImsiDone(const AppExecFwk::InnerEvent::Pointer & event)134 bool IsimFile::ProcessGetImsiDone(const AppExecFwk::InnerEvent::Pointer &event)
135 {
136     std::shared_ptr<std::string> sharedObject = event->GetSharedObject<std::string>();
137     bool isFileHandleResponse = true;
138     if (sharedObject != nullptr) {
139         imsi_ = *sharedObject;
140         TELEPHONY_LOGI("IsimFile::ProcessEvent MSG_SIM_OBTAIN_IMSI_DONE");
141         if (!imsi_.empty()) {
142             imsiReadyObser_->NotifyObserver(RadioEvent::RADIO_IMSI_LOADED_READY);
143             PublishSimFileEvent(SIM_STATE_ACTION, ICC_STATE_IMSI, imsi_);
144         }
145     }
146     return isFileHandleResponse;
147 }
148 
InitMemberFunc()149 void IsimFile::InitMemberFunc()
150 {
151     memberFuncMap_[RadioEvent::RADIO_SIM_STATE_READY] = &IsimFile::ProcessIccReady;
152     memberFuncMap_[MSG_ICC_REFRESH] = &IsimFile::ProcessIsimRefresh;
153     memberFuncMap_[MSG_SIM_OBTAIN_IMSI_DONE] = &IsimFile::ProcessGetImsiDone;
154     memberFuncMap_[MSG_SIM_OBTAIN_ICCID_DONE] = &IsimFile::ProcessGetIccidDone;
155     memberFuncMap_[MSG_SIM_OBTAIN_IMPI_DONE] = &IsimFile::ProcessGetImpiDone;
156 }
157 
ProcessGetImpiDone(const AppExecFwk::InnerEvent::Pointer & event)158 bool IsimFile::ProcessGetImpiDone(const AppExecFwk::InnerEvent::Pointer &event)
159 {
160     std::unique_ptr<ControllerToFileMsg> fd = event->GetUniqueObject<ControllerToFileMsg>();
161     bool isFileProcessResponse = true;
162     if (fd->exception != nullptr) {
163         TELEPHONY_LOGE("ProcessGetImpiDone get exception");
164         return isFileProcessResponse ;
165     }
166     imsi_ = fd->resultData;
167     TELEPHONY_LOGI("IsimFile::ProcessGetImpiDone success");
168     return isFileProcessResponse;
169 }
170 
ObtainIsimImpi()171 std::string IsimFile::ObtainIsimImpi()
172 {
173     return impi_;
174 }
ObtainIsimDomain()175 std::string IsimFile::ObtainIsimDomain()
176 {
177     return domain_;
178 }
ObtainIsimImpu()179 std::string* IsimFile::ObtainIsimImpu()
180 {
181     return impu_;
182 }
ObtainIsimIst()183 std::string IsimFile::ObtainIsimIst()
184 {
185     return ist_;
186 }
ObtainIsimPcscf()187 std::string* IsimFile::ObtainIsimPcscf()
188 {
189     return pcscf_;
190 }
191 
UpdateVoiceMail(const std::string & mailName,const std::string & mailNumber)192 bool IsimFile::UpdateVoiceMail(const std::string &mailName, const std::string &mailNumber)
193 {
194     // cdma not support
195     return false;
196 }
197 
ObtainSpnCondition(bool roaming,const std::string & operatorNum)198 int IsimFile::ObtainSpnCondition(bool roaming, const std::string &operatorNum)
199 {
200     return 0;
201 }
202 
ObtainIsoCountryCode()203 std::string IsimFile::ObtainIsoCountryCode()
204 {
205     return "";
206 }
~IsimFile()207 IsimFile::~IsimFile() {}
208 } // namespace Telephony
209 } // namespace OHOS
210