1 /*
2 * Copyright (C) 2021-2022 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 "multi_sim_controller.h"
17
18 #include "common_event_manager.h"
19 #include "common_event_support.h"
20 #include "core_service_errors.h"
21 #include "core_service_hisysevent.h"
22 #include "parameters.h"
23 #include "string_ex.h"
24
25 namespace OHOS {
26 namespace Telephony {
27 static const int32_t DEFAULT_SLOT_ID = 0;
28 static const int32_t EVENT_CODE = 1;
29 static const int32_t ACTIVATABLE = 2;
30 static const int32_t RETRY_COUNT = 12;
31 static const int32_t RETRY_TIME = 5000;
32 static const int32_t IMS_SWITCH_VALUE_UNKNOWN = -1;
33 static const std::string PARAM_SLOTID = "slotId";
34 static const std::string DEFAULT_VOICE_SLOT_CHANGED = "defaultVoiceSlotChanged";
35 static const std::string DEFAULT_SMS_SLOT_CHANGED = "defaultSmsSlotChanged";
36 static const std::string DEFAULT_CELLULAR_DATA_SLOT_CHANGED = "defaultCellularDataChanged";
37 static const std::string DEFAULT_MAIN_SLOT_CHANGED = "defaultMainSlotChanged";
38
MultiSimController(std::shared_ptr<Telephony::ITelRilManager> telRilManager,std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager,std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager,const std::shared_ptr<AppExecFwk::EventRunner> & runner)39 MultiSimController::MultiSimController(std::shared_ptr<Telephony::ITelRilManager> telRilManager,
40 std::vector<std::shared_ptr<Telephony::SimStateManager>> simStateManager,
41 std::vector<std::shared_ptr<Telephony::SimFileManager>> simFileManager,
42 const std::shared_ptr<AppExecFwk::EventRunner> &runner)
43 : simStateManager_(simStateManager), simFileManager_(simFileManager)
44 {
45 TELEPHONY_LOGI("MultiSimController::MultiSimController");
46 radioProtocolController_ = std::make_shared<RadioProtocolController>(telRilManager, runner);
47 }
48
~MultiSimController()49 MultiSimController::~MultiSimController()
50 {
51 if (radioProtocolController_ != nullptr) {
52 radioProtocolController_->UnRegisterEvents();
53 }
54 }
55
56 // set all data to invalid wait for InitData to rebuild
Init()57 void MultiSimController::Init()
58 {
59 if (simDbHelper_ == nullptr) {
60 simDbHelper_ = std::make_unique<SimRdbHelper>();
61 }
62 if (radioProtocolController_ != nullptr) {
63 radioProtocolController_->Init();
64 }
65 maxCount_ = SIM_SLOT_COUNT;
66 TELEPHONY_LOGI("MultiSimController::Init Create SimRdbHelper count = %{public}d", maxCount_);
67 }
68
ForgetAllData()69 bool MultiSimController::ForgetAllData()
70 {
71 if (simDbHelper_ == nullptr) {
72 TELEPHONY_LOGE("MultiSimController::Init simDbHelper_ is nullptr failed");
73 return false;
74 }
75 ready_ = false;
76 int32_t result = INVALID_VALUE;
77 for (uint32_t i = 0; i <= RETRY_COUNT; i++) { // if we can not do ForgetAllData right,then nothing will be right
78 if (ready_) {
79 TELEPHONY_LOGI("MultiSimController::already ForgetAllData");
80 return true;
81 }
82 result = simDbHelper_->ForgetAllData();
83 std::this_thread::sleep_for(std::chrono::milliseconds(RETRY_TIME));
84 if (result != INVALID_VALUE) {
85 TELEPHONY_LOGI("MultiSimController::ForgetAllData complete");
86 ready_ = true;
87 return true;
88 }
89 }
90 TELEPHONY_LOGE("MultiSimController::get dataAbility error, is over");
91 return false;
92 }
93
ForgetAllData(int32_t slotId)94 bool MultiSimController::ForgetAllData(int32_t slotId)
95 {
96 if (simDbHelper_ == nullptr) {
97 TELEPHONY_LOGE("MultiSimController::ForgetAllData simDbHelper_ is nullptr");
98 return false;
99 }
100 return simDbHelper_->ForgetAllData(slotId) != INVALID_VALUE;
101 }
102
SetNetworkSearchManager(std::shared_ptr<INetworkSearch> networkSearchManager)103 void MultiSimController::SetNetworkSearchManager(std::shared_ptr<INetworkSearch> networkSearchManager)
104 {
105 networkSearchManager_ = networkSearchManager;
106 }
107
InitData(int32_t slotId)108 bool MultiSimController::InitData(int32_t slotId)
109 {
110 bool result = true;
111 if (!IsValidData(slotId)) {
112 TELEPHONY_LOGI("MultiSimController::InitData has no sim card, abandon");
113 return false;
114 }
115 if (!InitIccId(slotId)) { // check if we insert or reactive a data
116 TELEPHONY_LOGI("MultiSimController::InitData can not init IccId");
117 result = false;
118 }
119 if (!GetListFromDataBase()) { // init data base to local cache
120 TELEPHONY_LOGE("MultiSimController::InitData can not get dataBase");
121 result = false;
122 }
123 if (localCacheInfo_.size() <= 0) {
124 TELEPHONY_LOGE("MultiSimController::we get nothing from init");
125 return false;
126 }
127 if (!InitActive(slotId)) {
128 TELEPHONY_LOGE("MultiSimController::InitData InitActive failed");
129 result = false;
130 }
131 if (!InitShowName(slotId)) {
132 TELEPHONY_LOGE("MultiSimController::InitData InitShowName failed");
133 result = false;
134 }
135 if (!InitShowNumber(slotId)) {
136 TELEPHONY_LOGE("MultiSimController::InitData InitShowNumber failed");
137 result = false;
138 }
139 return result;
140 }
141
InitActive(int slotId)142 bool MultiSimController::InitActive(int slotId)
143 {
144 bool result = true;
145 if (!IsSimActive(slotId) && simStateManager_[slotId]->HasSimCard()) {
146 // force set to database ACTIVE and avoid duplicate
147 result = (SetActiveSim(slotId, ACTIVE, true) == TELEPHONY_ERR_SUCCESS);
148 }
149 if (IsSimActive(slotId) && !simStateManager_[slotId]->HasSimCard()) {
150 if (result && (SetActiveSim(slotId, DEACTIVE, true) == TELEPHONY_ERR_SUCCESS)) {
151 result = true;
152 } else {
153 result = false;
154 } // force set to database DEACTIVE and avoid duplicate
155 }
156 return result;
157 }
158
InitIccId(int slotId)159 bool MultiSimController::InitIccId(int slotId)
160 {
161 std::lock_guard<std::mutex> lock(mutex_);
162 if (simFileManager_[slotId] == nullptr) {
163 TELEPHONY_LOGE("MultiSimController::InitIccId can not get simFileManager");
164 return false;
165 }
166 std::string newIccId = Str16ToStr8(simFileManager_[slotId]->GetSimIccId());
167 if (newIccId.empty()) {
168 TELEPHONY_LOGE("MultiSimController::InitIccId can not get iccId");
169 return false;
170 }
171 if (simDbHelper_ == nullptr) {
172 TELEPHONY_LOGE("MultiSimController::InitIccId failed by nullptr");
173 return false;
174 }
175 int32_t result;
176 SimRdbInfo simRdbInfo;
177 simDbHelper_->QueryDataByIccId(newIccId, simRdbInfo);
178 if (!simRdbInfo.iccId.empty()) { // already have this card, reactive it
179 result = UpdateDataByIccId(slotId, newIccId);
180 } else { // insert a new data for new IccId
181 result = InsertData(slotId, newIccId);
182 }
183 if (result == INVALID_VALUE) {
184 TELEPHONY_LOGE("MultiSimController::InitIccId failed to init data");
185 return false;
186 } else {
187 return true;
188 }
189 }
190
UpdateDataByIccId(int slotId,const std::string & newIccId)191 int32_t MultiSimController::UpdateDataByIccId(int slotId, const std::string &newIccId)
192 {
193 if (simDbHelper_ == nullptr) {
194 TELEPHONY_LOGE("MultiSimController::UpdateDataByIccId failed by nullptr");
195 return INVALID_VALUE;
196 }
197 SimRdbInfo simRdbInfo;
198 simDbHelper_->QueryDataByIccId(newIccId, simRdbInfo);
199 NativeRdb::ValuesBucket values;
200 values.PutInt(SimRdbInfo::SLOT_INDEX, slotId);
201 values.PutInt(SimRdbInfo::IS_ACTIVE, ACTIVE);
202 const int32_t slotSingle = 1;
203 if (SIM_SLOT_COUNT == slotSingle) {
204 values.PutInt(SimData::IS_MAIN_CARD, MAIN_CARD);
205 values.PutInt(SimData::IS_VOICE_CARD, MAIN_CARD);
206 values.PutInt(SimData::IS_MESSAGE_CARD, MAIN_CARD);
207 values.PutInt(SimData::IS_CELLULAR_DATA_CARD, MAIN_CARD);
208 }
209 return simDbHelper_->UpdateDataByIccId(newIccId, values); // finish re active
210 }
211
InsertData(int slotId,const std::string & newIccId)212 int32_t MultiSimController::InsertData(int slotId, const std::string &newIccId)
213 {
214 if (simDbHelper_ == nullptr) {
215 TELEPHONY_LOGE("MultiSimController::InsertData failed by nullptr");
216 return INVALID_VALUE;
217 }
218 SimRdbInfo simRdbInfo;
219 simDbHelper_->QueryDataByIccId(newIccId, simRdbInfo);
220 NativeRdb::ValuesBucket values;
221 values.PutInt(SimRdbInfo::SLOT_INDEX, slotId);
222 values.PutString(SimRdbInfo::ICC_ID, newIccId);
223 values.PutString(SimRdbInfo::CARD_ID, newIccId); // iccId == cardId by now
224 values.PutInt(SimRdbInfo::IS_ACTIVE, ACTIVE);
225 const int32_t slotSingle = 1;
226 if (SIM_SLOT_COUNT == slotSingle) {
227 values.PutInt(SimData::IS_MAIN_CARD, MAIN_CARD);
228 values.PutInt(SimData::IS_VOICE_CARD, MAIN_CARD);
229 values.PutInt(SimData::IS_MESSAGE_CARD, MAIN_CARD);
230 values.PutInt(SimData::IS_CELLULAR_DATA_CARD, MAIN_CARD);
231 } else {
232 values.PutInt(SimData::IS_MAIN_CARD, NOT_MAIN);
233 values.PutInt(SimData::IS_VOICE_CARD, NOT_MAIN);
234 values.PutInt(SimData::IS_MESSAGE_CARD, NOT_MAIN);
235 values.PutInt(SimData::IS_CELLULAR_DATA_CARD, NOT_MAIN);
236 }
237 int64_t id;
238 return simDbHelper_->InsertData(id, values);
239 }
240
InitShowName(int slotId)241 bool MultiSimController::InitShowName(int slotId)
242 {
243 std::u16string showName;
244 GetShowName(slotId, showName);
245 if (!showName.empty() && showName != IccAccountInfo::DEFAULT_SHOW_NAME) {
246 TELEPHONY_LOGI("MultiSimController::InitShowName no need to Init again");
247 return true;
248 }
249 if (networkSearchManager_ == nullptr) {
250 TELEPHONY_LOGE("MultiSimController::InitShowName failed by nullptr");
251 return false;
252 }
253 networkSearchManager_->GetOperatorName(slotId, showName);
254 int32_t result = TELEPHONY_ERROR;
255 if (!showName.empty()) {
256 result = SetShowName(slotId, showName, true);
257 } else {
258 result = SetShowName(slotId, IccAccountInfo::DEFAULT_SHOW_NAME, true);
259 }
260 return result == TELEPHONY_ERR_SUCCESS;
261 }
262
InitShowNumber(int slotId)263 bool MultiSimController::InitShowNumber(int slotId)
264 {
265 std::u16string showNumber;
266 GetShowNumber(slotId, showNumber);
267 if (!showNumber.empty() && showNumber != IccAccountInfo::DEFAULT_SHOW_NUMBER) {
268 TELEPHONY_LOGI("MultiSimController::InitShowNumber no need to Init again");
269 return true;
270 }
271 if (simFileManager_[slotId] == nullptr) {
272 TELEPHONY_LOGE("can not get simFileManager");
273 return false;
274 }
275 showNumber = simFileManager_[slotId]->GetSimTelephoneNumber();
276 int32_t result = TELEPHONY_ERROR;
277 if (!showNumber.empty()) {
278 result = SetShowNumber(slotId, showNumber, true);
279 } else {
280 result = SetShowNumber(slotId, IccAccountInfo::DEFAULT_SHOW_NUMBER, true);
281 }
282 return result == TELEPHONY_ERR_SUCCESS;
283 }
284
GetListFromDataBase()285 bool MultiSimController::GetListFromDataBase()
286 {
287 TELEPHONY_LOGI("MultiSimController::GetListFromDataBase");
288 std::lock_guard<std::mutex> lock(mutex_);
289 if (localCacheInfo_.size() > 0) {
290 localCacheInfo_.clear();
291 }
292 if (simDbHelper_ == nullptr) {
293 TELEPHONY_LOGE("MultiSimController::GetListFromDataBase failed by nullptr");
294 return false;
295 }
296 int32_t result = simDbHelper_->QueryAllValidData(localCacheInfo_);
297 SortCache();
298 return (result != INVALID_VALUE) ? true : false;
299 }
300
SortCache()301 void MultiSimController::SortCache()
302 {
303 size_t count = localCacheInfo_.size();
304 TELEPHONY_LOGI("MultiSimController::SortCache count = %{public}lu", static_cast<unsigned long>(count));
305 if (count <= 0) {
306 TELEPHONY_LOGE("MultiSimController::Sort empty");
307 return;
308 }
309 std::vector<SimRdbInfo> sortCache;
310 SimRdbInfo emptyUnit;
311 emptyUnit.isActive = DEACTIVE;
312 emptyUnit.iccId = "";
313 for (int i = 0; i < maxCount_; i++) {
314 emptyUnit.slotIndex = i;
315 sortCache.emplace_back(emptyUnit);
316 }
317 for (size_t j = 0; j < count; j++) {
318 TELEPHONY_LOGI("MultiSimController::index = %{public}d j = %{public}lu", localCacheInfo_[j].slotIndex,
319 static_cast<unsigned long>(j));
320 sortCache[localCacheInfo_[j].slotIndex] = localCacheInfo_[j];
321 }
322 localCacheInfo_ = sortCache;
323 }
324
325 /*
326 * check the data is valid, if we don't have SimCard the data is not valid
327 */
IsValidData(int32_t slotId)328 bool MultiSimController::IsValidData(int32_t slotId)
329 {
330 if (((slotId < DEFAULT_SIM_SLOT_ID) || (slotId >= SIM_SLOT_COUNT)) || simStateManager_[slotId] == nullptr) {
331 TELEPHONY_LOGE("MultiSimController::IsValidData can not get simStateManager");
332 return false;
333 }
334 return simStateManager_[slotId]->HasSimCard();
335 }
336
RefreshActiveIccAccountInfoList()337 bool MultiSimController::RefreshActiveIccAccountInfoList()
338 {
339 std::lock_guard<std::mutex> lock(mutex_);
340 if (localCacheInfo_.empty()) {
341 TELEPHONY_LOGE("MultiSimController::RefreshActiveIccAccountInfoList failed by invalid data");
342 return false;
343 }
344 std::vector<SimRdbInfo>::iterator it = localCacheInfo_.begin();
345 if (iccAccountInfoList_.size() > 0) {
346 iccAccountInfoList_.clear();
347 }
348 while (it != localCacheInfo_.end()) { // loop data list
349 if (it->isActive == ACTIVE) { // pick Active item
350 iccAccountInfo_.Init(it->simId, it->slotIndex);
351 iccAccountInfo_.showName = Str8ToStr16(it->showName);
352 iccAccountInfo_.showNumber = Str8ToStr16(it->phoneNumber);
353 iccAccountInfo_.iccId = Str8ToStr16(it->iccId);
354 iccAccountInfo_.isActive = it->isActive;
355 iccAccountInfoList_.emplace_back(iccAccountInfo_);
356 }
357 ++it;
358 }
359 return true;
360 }
361
GetSlotId(int32_t simId)362 int32_t MultiSimController::GetSlotId(int32_t simId)
363 {
364 if (localCacheInfo_.empty()) {
365 TELEPHONY_LOGE("MultiSimController::GetSlotId failed by nullptr");
366 return INVALID_VALUE;
367 }
368 std::lock_guard<std::mutex> lock(mutex_);
369 std::vector<SimRdbInfo>::iterator it = localCacheInfo_.begin();
370
371 while (it != localCacheInfo_.end()) { // loop data list
372 if (it->isActive == ACTIVE && it->simId == simId) { // pick Active item
373 return it->slotIndex;
374 }
375 ++it;
376 }
377 return INVALID_VALUE;
378 }
379
IsSimActive(int32_t slotId)380 bool MultiSimController::IsSimActive(int32_t slotId)
381 {
382 std::lock_guard<std::mutex> lock(mutex_);
383 if (!IsValidData(slotId)) {
384 TELEPHONY_LOGE("MultiSimController::IsSimActive InValidData");
385 return false;
386 }
387 if (static_cast<uint32_t>(slotId) >= localCacheInfo_.size()) {
388 TELEPHONY_LOGE("MultiSimController::IsSimActive failed by out of range");
389 return false;
390 }
391 return localCacheInfo_[slotId].isActive == ACTIVE ? true : false;
392 }
393
IsSimActivatable(int32_t slotId)394 bool MultiSimController::IsSimActivatable(int32_t slotId)
395 {
396 std::lock_guard<std::mutex> lock(mutex_);
397 if (static_cast<uint32_t>(slotId) >= localCacheInfo_.size()) {
398 TELEPHONY_LOGE("MultiSimController::IsSimActivatable failed by out of range");
399 return false;
400 }
401 return localCacheInfo_[slotId].isActive == ACTIVATABLE ? true : false;
402 }
403
SetActiveSim(int32_t slotId,int32_t enable,bool force)404 int32_t MultiSimController::SetActiveSim(int32_t slotId, int32_t enable, bool force)
405 {
406 TELEPHONY_LOGI("MultiSimController::SetActiveSim enable = %{public}d slotId = %{public}d", enable, slotId);
407 if (!IsValidData(slotId)) {
408 TELEPHONY_LOGE("MultiSimController::SetActiveSim invalid slotid or sim card absent.");
409 return TELEPHONY_ERR_NO_SIM_CARD;
410 }
411 if (!force && GetIccId(slotId).empty() && enable != ACTIVE) { // force is used for init data
412 TELEPHONY_LOGE("MultiSimController::SetActiveSim empty sim operation set failed");
413 return TELEPHONY_ERR_ARGUMENT_INVALID;
414 }
415 if (static_cast<uint32_t>(slotId) >= localCacheInfo_.size() && enable != ACTIVE) {
416 TELEPHONY_LOGE("MultiSimController::SetActiveSim failed by out of range");
417 return TELEPHONY_ERR_ARGUMENT_INVALID;
418 }
419 if (!force && !SetActiveSimToRil(slotId, ENTITY_CARD, enable)) {
420 TELEPHONY_LOGE("MultiSimController::SetActiveSim SetActiveSimToRil failed");
421 return TELEPHONY_ERR_RIL_CMD_FAIL;
422 }
423 if (simDbHelper_ == nullptr) {
424 TELEPHONY_LOGE("MultiSimController::SetActiveSim failed by nullptr");
425 return TELEPHONY_ERR_LOCAL_PTR_NULL;
426 }
427 std::lock_guard<std::mutex> lock(mutex_);
428 NativeRdb::ValuesBucket values;
429 values.PutInt(SimRdbInfo::IS_ACTIVE, enable);
430 int32_t result = simDbHelper_->UpdateDataBySlotId(slotId, values);
431 if (result == INVALID_VALUE) {
432 TELEPHONY_LOGE("MultiSimController::SetActiveSim failed by database");
433 return TELEPHONY_ERR_DATABASE_WRITE_FAIL;
434 }
435 if (enable == ACTIVE) {
436 localCacheInfo_[slotId].isActive = enable;
437 } else {
438 localCacheInfo_[slotId].isActive = ACTIVATABLE;
439 }
440 return TELEPHONY_ERR_SUCCESS;
441 }
442
SetActiveSimToRil(int32_t slotId,int32_t type,int32_t enable)443 bool MultiSimController::SetActiveSimToRil(int32_t slotId, int32_t type, int32_t enable)
444 {
445 if (radioProtocolController_ == nullptr) {
446 TELEPHONY_LOGE("MultiSimController::SetActiveSim radioProtocolController_ is nullptr");
447 return false;
448 }
449 std::unique_lock<std::mutex> lck(radioProtocolController_->ctx_);
450 radioProtocolController_->RadioProtocolControllerWait();
451 if (!radioProtocolController_->SetActiveSimToRil(slotId, type, enable)) {
452 TELEPHONY_LOGE("MultiSimController::SetActiveSimToRil failed");
453 return false;
454 }
455 while (!radioProtocolController_->RadioProtocolControllerPoll()) {
456 TELEPHONY_LOGI("MultiSimController SetActiveSimToRil wait");
457 radioProtocolController_->cv_.wait(lck);
458 }
459 return radioProtocolController_->GetActiveSimToRilResult() == static_cast<int32_t>(HRilErrType::NONE);
460 }
461
GetSimAccountInfo(int32_t slotId,IccAccountInfo & info)462 int32_t MultiSimController::GetSimAccountInfo(int32_t slotId, IccAccountInfo &info)
463 {
464 std::lock_guard<std::mutex> lock(mutex_);
465 if (!IsValidData(slotId)) {
466 TELEPHONY_LOGE("MultiSimController::GetSimAccountInfo InValidData");
467 return TELEPHONY_ERR_NO_SIM_CARD;
468 }
469 if (static_cast<uint32_t>(slotId) >= localCacheInfo_.size()) {
470 TELEPHONY_LOGE("MultiSimController::GetSimAccountInfo failed by out of range");
471 return TELEPHONY_ERR_SLOTID_INVALID;
472 }
473 if (localCacheInfo_[slotId].iccId.empty()) {
474 TELEPHONY_LOGE("MultiSimController::GetSimAccountInfo failed by no data");
475 return CORE_ERR_SIM_CARD_LOAD_FAILED;
476 }
477 info.slotIndex = localCacheInfo_[slotId].slotIndex;
478 info.simId = localCacheInfo_[slotId].simId;
479 info.isActive = localCacheInfo_[slotId].isActive;
480 info.showName = Str8ToStr16(localCacheInfo_[slotId].showName);
481 info.showNumber = Str8ToStr16(localCacheInfo_[slotId].phoneNumber);
482 info.iccId = Str8ToStr16(localCacheInfo_[slotId].iccId);
483 info.isEsim = false;
484 return TELEPHONY_ERR_SUCCESS;
485 }
486
GetDefaultVoiceSlotId()487 int32_t MultiSimController::GetDefaultVoiceSlotId()
488 {
489 TELEPHONY_LOGI("MultiSimController::GetDefaultVoiceSlotId");
490 std::lock_guard<std::mutex> lock(mutex_);
491 if (localCacheInfo_.empty()) {
492 TELEPHONY_LOGE("MultiSimController::GetDefaultVoiceSlotId failed by nullptr");
493 if (simDbHelper_ == nullptr) {
494 TELEPHONY_LOGE("MultiSimController::GetDefaultVoiceSlotId simDbHelper is nullptr");
495 return DEFAULT_SLOT_ID;
496 }
497 return simDbHelper_->GetDefaultVoiceCardSlotId();
498 }
499 int32_t i = DEFAULT_SIM_SLOT_ID;
500 for (; i < maxCount_; i++) {
501 if (localCacheInfo_[i].isVoiceCard == MAIN_CARD) {
502 return i;
503 }
504 }
505 return GetFirstActivedSlotId();
506 }
507
GetFirstActivedSlotId()508 int32_t MultiSimController::GetFirstActivedSlotId()
509 {
510 TELEPHONY_LOGI("MultiSimController::GetFirstActivedSlotId");
511 int32_t i = DEFAULT_SIM_SLOT_ID;
512 for (; i < maxCount_; i++) {
513 if (localCacheInfo_[i].isActive == ACTIVE) {
514 return localCacheInfo_[i].slotIndex;
515 }
516 }
517 return INVALID_VALUE;
518 }
519
SetDefaultVoiceSlotId(int32_t slotId)520 int32_t MultiSimController::SetDefaultVoiceSlotId(int32_t slotId)
521 {
522 TELEPHONY_LOGI("MultiSimController::SetDefaultVoiceSlotId slotId = %{public}d", slotId);
523 if ((slotId == DEFAULT_SIM_SLOT_ID_REMOVE && localCacheInfo_.empty()) ||
524 (slotId != DEFAULT_SIM_SLOT_ID_REMOVE && !IsValidData(slotId))) {
525 TELEPHONY_LOGE("MultiSimController::SetDefaultVoiceSlotId no sim card");
526 return TELEPHONY_ERR_NO_SIM_CARD;
527 }
528 if (slotId != DEFAULT_SIM_SLOT_ID_REMOVE && !IsSimActive(slotId)) {
529 TELEPHONY_LOGE("MultiSimController::SetDefaultVoiceSlotId slotId is not active");
530 return CORE_SERVICE_SIM_CARD_IS_NOT_ACTIVE;
531 }
532 if (slotId >= (int32_t)localCacheInfo_.size() || slotId < DEFAULT_SIM_SLOT_ID_REMOVE) {
533 TELEPHONY_LOGE("MultiSimController::SetDefaultVoiceSlotId failed by out of range");
534 return TELEPHONY_ERR_SLOTID_INVALID;
535 }
536 if (simDbHelper_ == nullptr) {
537 TELEPHONY_LOGE("MultiSimController::SetDefaultVoiceSlotId failed by nullptr");
538 return TELEPHONY_ERR_LOCAL_PTR_NULL;
539 }
540 std::lock_guard<std::mutex> lock(mutex_);
541 int32_t result = simDbHelper_->SetDefaultVoiceCard(slotId);
542 if (result == INVALID_VALUE) {
543 TELEPHONY_LOGE("MultiSimController::SetDefaultVoiceSlotId get Data Base failed");
544 return TELEPHONY_ERR_DATABASE_WRITE_FAIL;
545 }
546 int32_t i = DEFAULT_SIM_SLOT_ID;
547 for (; i < maxCount_; i++) { // save to cache
548 if (slotId == i) {
549 localCacheInfo_[i].isVoiceCard = MAIN_CARD;
550 continue;
551 }
552 localCacheInfo_[i].isVoiceCard = NOT_MAIN;
553 }
554 if (!AnnounceDefaultVoiceSlotIdChanged(slotId)) {
555 return TELEPHONY_ERR_PUBLISH_BROADCAST_FAIL;
556 }
557 return TELEPHONY_ERR_SUCCESS;
558 }
559
GetDefaultSmsSlotId()560 int32_t MultiSimController::GetDefaultSmsSlotId()
561 {
562 TELEPHONY_LOGI("MultiSimController::GetDefaultSmsSlotId");
563 std::lock_guard<std::mutex> lock(mutex_);
564 if (localCacheInfo_.empty()) {
565 TELEPHONY_LOGE("MultiSimController::GetDefaultSmsSlotId failed by nullptr");
566 if (simDbHelper_ == nullptr) {
567 TELEPHONY_LOGE("MultiSimController::GetDefaultSmsSlotId simDbHelper is nullptr");
568 return DEFAULT_SLOT_ID;
569 }
570 return simDbHelper_->GetDefaultMessageCardSlotId();
571 }
572 int32_t i = DEFAULT_SIM_SLOT_ID;
573 for (; i < maxCount_; i++) {
574 if (localCacheInfo_[i].isMessageCard == MAIN_CARD) {
575 return i;
576 }
577 }
578 return GetFirstActivedSlotId();
579 }
580
SetDefaultSmsSlotId(int32_t slotId)581 int32_t MultiSimController::SetDefaultSmsSlotId(int32_t slotId)
582 {
583 if (slotId == DEFAULT_SIM_SLOT_ID_REMOVE && localCacheInfo_.empty()) {
584 TELEPHONY_LOGE("MultiSimController::SetDefaultSmsSlotId no sim card");
585 return TELEPHONY_ERR_NO_SIM_CARD;
586 }
587 if (slotId != DEFAULT_SIM_SLOT_ID_REMOVE && !IsSimActive(slotId)) {
588 TELEPHONY_LOGE("MultiSimController::SetDefaultSmsSlotId slotId is not active!");
589 return CORE_SERVICE_SIM_CARD_IS_NOT_ACTIVE;
590 }
591 if (slotId >= (int32_t)localCacheInfo_.size() || slotId < DEFAULT_SIM_SLOT_ID_REMOVE) {
592 TELEPHONY_LOGE("MultiSimController::SetDefaultSmsSlotId failed by out of range");
593 return TELEPHONY_ERR_SLOTID_INVALID;
594 }
595 if (simDbHelper_ == nullptr) {
596 TELEPHONY_LOGE("MultiSimController::SetDefaultSmsSlotId failed by nullptr");
597 return TELEPHONY_ERR_LOCAL_PTR_NULL;
598 }
599 std::lock_guard<std::mutex> lock(mutex_);
600 int32_t result = simDbHelper_->SetDefaultMessageCard(slotId);
601 if (result == INVALID_VALUE) {
602 TELEPHONY_LOGE("MultiSimController::SetDefaultSmsSlotId get Data Base failed");
603 return TELEPHONY_ERR_DATABASE_WRITE_FAIL;
604 }
605 int32_t i = DEFAULT_SIM_SLOT_ID;
606 for (; i < maxCount_; i++) { // save to cache
607 if (slotId == i) {
608 localCacheInfo_[i].isMessageCard = MAIN_CARD;
609 continue;
610 }
611 localCacheInfo_[i].isMessageCard = NOT_MAIN;
612 }
613 if (!AnnounceDefaultSmsSlotIdChanged(slotId)) {
614 return TELEPHONY_ERR_PUBLISH_BROADCAST_FAIL;
615 }
616 return TELEPHONY_ERR_SUCCESS;
617 }
618
GetDefaultCellularDataSlotId()619 int32_t MultiSimController::GetDefaultCellularDataSlotId()
620 {
621 TELEPHONY_LOGI("MultiSimController::GetDefaultCellularDataSlotId");
622 std::lock_guard<std::mutex> lock(mutex_);
623 return GetDefaultCellularDataSlotIdUnit();
624 }
625
SetDefaultCellularDataSlotId(int32_t slotId)626 int32_t MultiSimController::SetDefaultCellularDataSlotId(int32_t slotId)
627 {
628 TELEPHONY_LOGI("MultiSimController::SetDefaultCellularDataSlotId slotId = %{public}d", slotId);
629 if ((slotId == DEFAULT_SIM_SLOT_ID_REMOVE && localCacheInfo_.empty()) ||
630 (slotId != DEFAULT_SIM_SLOT_ID_REMOVE && !IsValidData(slotId))) {
631 TELEPHONY_LOGE("MultiSimController::SetDefaultCellularDataSlotId no sim card");
632 return TELEPHONY_ERR_NO_SIM_CARD;
633 }
634 if (slotId != DEFAULT_SIM_SLOT_ID_REMOVE && !IsSimActive(slotId)) {
635 TELEPHONY_LOGE("MultiSimController::SetDefaultCellularDataSlotId slotId is not active");
636 return CORE_SERVICE_SIM_CARD_IS_NOT_ACTIVE;
637 }
638 if (slotId >= (int32_t)localCacheInfo_.size() || slotId < DEFAULT_SIM_SLOT_ID_REMOVE) {
639 TELEPHONY_LOGE("MultiSimController::SetDefaultCellularDataSlotId failed by out of range");
640 return TELEPHONY_ERR_SLOTID_INVALID;
641 }
642 if (simDbHelper_ == nullptr) {
643 TELEPHONY_LOGE("MultiSimController::SetDefaultCellularDataSlotId failed by nullptr");
644 return TELEPHONY_ERR_LOCAL_PTR_NULL;
645 }
646 std::lock_guard<std::mutex> lock(mutex_);
647 int32_t result = simDbHelper_->SetDefaultCellularData(slotId);
648 if (result == INVALID_VALUE) {
649 TELEPHONY_LOGE("MultiSimController::SetDefaultCellularDataSlotId get Data Base failed");
650 return TELEPHONY_ERR_DATABASE_WRITE_FAIL;
651 }
652 int32_t i = DEFAULT_SIM_SLOT_ID;
653 for (; i < maxCount_; i++) { // save to cache
654 if (slotId == i) {
655 localCacheInfo_[i].isCellularDataCard = MAIN_CARD;
656 continue;
657 }
658 localCacheInfo_[i].isCellularDataCard = NOT_MAIN;
659 }
660 CoreServiceHiSysEvent::WriteDefaultDataSlotIdBehaviorEvent(slotId);
661 if (!AnnounceDefaultCellularDataSlotIdChanged(slotId)) {
662 TELEPHONY_LOGE("MultiSimController::SetDefaultCellularDataSlotId publish broadcast failed");
663 return TELEPHONY_ERR_PUBLISH_BROADCAST_FAIL;
664 }
665 return TELEPHONY_ERR_SUCCESS;
666 }
667
GetDefaultCellularDataSlotIdUnit()668 int32_t MultiSimController::GetDefaultCellularDataSlotIdUnit()
669 {
670 TELEPHONY_LOGI("MultiSimController::GetDefaultCellularDataSlotId");
671 if (localCacheInfo_.empty()) {
672 TELEPHONY_LOGE("MultiSimController::GetDefaultCellularDataSlotId failed by nullptr");
673 if (simDbHelper_ == nullptr) {
674 TELEPHONY_LOGE("MultiSimController::GetDefaultCellularDataSlotIdUnit simDbHelper is nullptr");
675 return DEFAULT_SLOT_ID;
676 }
677 return simDbHelper_->GetDefaultCellularDataCardSlotId();
678 }
679 int32_t i = DEFAULT_SIM_SLOT_ID;
680 for (; i < maxCount_; i++) {
681 if (localCacheInfo_[i].isCellularDataCard == MAIN_CARD) {
682 return i;
683 }
684 }
685 return GetFirstActivedSlotId();
686 }
687
GetPrimarySlotId()688 int32_t MultiSimController::GetPrimarySlotId()
689 {
690 TELEPHONY_LOGI("MultiSimController::GetPrimarySlotId");
691 std::lock_guard<std::mutex> lock(mutex_);
692 if (localCacheInfo_.empty()) {
693 if (simDbHelper_ == nullptr) {
694 TELEPHONY_LOGE("MultiSimController::SetPrimarySlotId failed by nullptr");
695 return DEFAULT_SLOT_ID;
696 }
697 return simDbHelper_->GetDefaultMainCardSlotId();
698 }
699 int32_t i = DEFAULT_SIM_SLOT_ID;
700 for (; i < maxCount_; i++) {
701 if (localCacheInfo_[i].isMainCard == MAIN_CARD) {
702 return i;
703 }
704 }
705 return GetDefaultCellularDataSlotIdUnit();
706 }
707
SetPrimarySlotId(int32_t slotId)708 int32_t MultiSimController::SetPrimarySlotId(int32_t slotId)
709 {
710 if (localCacheInfo_.empty() || !IsValidData(slotId)) {
711 TELEPHONY_LOGE("MultiSimController::SetPrimarySlotId no sim card");
712 return TELEPHONY_ERR_NO_SIM_CARD;
713 }
714 if (static_cast<uint32_t>(slotId) >= localCacheInfo_.size()) {
715 TELEPHONY_LOGE("MultiSimController::SetPrimarySlotId failed by out of range");
716 return TELEPHONY_ERR_SLOTID_INVALID;
717 }
718 if (!IsSimActive(slotId)) {
719 TELEPHONY_LOGE("MultiSimController::SetPrimarySlotId slotId is not active");
720 return CORE_SERVICE_SIM_CARD_IS_NOT_ACTIVE;
721 }
722 // change protocol for default cellulardata slotId
723 if (radioProtocolController_ == nullptr || !radioProtocolController_->SetRadioProtocol(slotId)) {
724 TELEPHONY_LOGE("MultiSimController::SetPrimarySlotId SetRadioProtocol failed");
725 return TELEPHONY_ERR_LOCAL_PTR_NULL;
726 }
727 if (simDbHelper_ == nullptr) {
728 TELEPHONY_LOGE("MultiSimController::SetPrimarySlotId failed by nullptr");
729 return TELEPHONY_ERR_LOCAL_PTR_NULL;
730 }
731 std::lock_guard<std::mutex> lock(mutex_);
732 int32_t setMainResult = simDbHelper_->SetDefaultMainCard(slotId);
733 int32_t setDataResult = simDbHelper_->SetDefaultCellularData(slotId);
734 if (setMainResult == INVALID_VALUE || setDataResult == INVALID_VALUE) {
735 TELEPHONY_LOGE("MultiSimController::SetPrimarySlotId failed by invalid result");
736 return TELEPHONY_ERR_DATABASE_WRITE_FAIL;
737 }
738 int32_t i = DEFAULT_SIM_SLOT_ID;
739 for (; i < maxCount_; i++) { // save to cache
740 if (slotId == i) {
741 localCacheInfo_[i].isMainCard = MAIN_CARD;
742 localCacheInfo_[i].isCellularDataCard = MAIN_CARD;
743 continue;
744 }
745 localCacheInfo_[i].isMainCard = NOT_MAIN;
746 localCacheInfo_[i].isCellularDataCard = NOT_MAIN;
747 }
748 if (!AnnounceDefaultMainSlotIdChanged(slotId)) {
749 TELEPHONY_LOGE("MultiSimController::SetPrimarySlotId publish broadcast failed");
750 return TELEPHONY_ERR_PUBLISH_BROADCAST_FAIL;
751 }
752 return TELEPHONY_ERR_SUCCESS;
753 }
754
GetShowNumber(int32_t slotId,std::u16string & showNumber)755 int32_t MultiSimController::GetShowNumber(int32_t slotId, std::u16string &showNumber)
756 {
757 std::lock_guard<std::mutex> lock(mutex_);
758 if (!IsValidData(slotId)) {
759 TELEPHONY_LOGE("MultiSimController::GetShowNumber InValidData");
760 return TELEPHONY_ERR_NO_SIM_CARD;
761 }
762 if (static_cast<uint32_t>(slotId) >= localCacheInfo_.size()) {
763 TELEPHONY_LOGE("MultiSimController::GetShowNumber failed by nullptr");
764 return TELEPHONY_ERR_ARGUMENT_INVALID;
765 }
766 showNumber = Str8ToStr16(localCacheInfo_[slotId].phoneNumber);
767 return TELEPHONY_ERR_SUCCESS;
768 }
769
SetShowNumber(int32_t slotId,std::u16string number,bool force)770 int32_t MultiSimController::SetShowNumber(int32_t slotId, std::u16string number, bool force)
771 {
772 TELEPHONY_LOGI("MultiSimController::SetShowNumber slotId = %{public}d", slotId);
773 if (!force && !IsValidData(slotId)) {
774 TELEPHONY_LOGE("MultiSimController::SetShowNumber InValidData");
775 return TELEPHONY_ERR_NO_SIM_CARD;
776 }
777 if ((static_cast<uint32_t>(slotId) >= localCacheInfo_.size()) || (!force && GetIccId(slotId).empty())) {
778 TELEPHONY_LOGE("MultiSimController::SetShowNumber failed by out of range");
779 return TELEPHONY_ERR_ARGUMENT_INVALID;
780 }
781 if (simDbHelper_ == nullptr) {
782 TELEPHONY_LOGE("MultiSimController::SetShowNumber failed by nullptr");
783 return TELEPHONY_ERR_LOCAL_PTR_NULL;
784 }
785 std::lock_guard<std::mutex> lock(mutex_);
786 NativeRdb::ValuesBucket values;
787 values.PutString(SimRdbInfo::PHONE_NUMBER, Str16ToStr8(number));
788 int32_t result = simDbHelper_->UpdateDataBySlotId(slotId, values);
789 if (result == INVALID_VALUE) {
790 TELEPHONY_LOGE("MultiSimController::SetShowNumber set Data Base failed");
791 return TELEPHONY_ERR_DATABASE_WRITE_FAIL;
792 }
793 localCacheInfo_[slotId].phoneNumber = Str16ToStr8(number); // save to cache
794 return TELEPHONY_ERR_SUCCESS;
795 }
796
GetShowName(int32_t slotId,std::u16string & showName)797 int32_t MultiSimController::GetShowName(int32_t slotId, std::u16string &showName)
798 {
799 std::lock_guard<std::mutex> lock(mutex_);
800 if (!IsValidData(slotId)) {
801 TELEPHONY_LOGE("MultiSimController::GetShowNumber InValidData");
802 return TELEPHONY_ERR_NO_SIM_CARD;
803 }
804 if (static_cast<uint32_t>(slotId) >= localCacheInfo_.size()) {
805 TELEPHONY_LOGE("MultiSimController::GetShowName failed by nullptr");
806 return TELEPHONY_ERR_ARGUMENT_INVALID;
807 }
808 showName = Str8ToStr16(localCacheInfo_[slotId].showName);
809 return TELEPHONY_ERR_SUCCESS;
810 }
811
SetShowName(int32_t slotId,std::u16string name,bool force)812 int32_t MultiSimController::SetShowName(int32_t slotId, std::u16string name, bool force)
813 {
814 if (!force && !IsValidData(slotId)) {
815 TELEPHONY_LOGE("MultiSimController::SetShowNumber InValidData");
816 return TELEPHONY_ERR_NO_SIM_CARD;
817 }
818 if ((static_cast<uint32_t>(slotId) >= localCacheInfo_.size()) || (!force && GetIccId(slotId).empty())) {
819 TELEPHONY_LOGE("MultiSimController::SetShowName failed by out of range");
820 return TELEPHONY_ERR_ARGUMENT_INVALID;
821 }
822 if (simDbHelper_ == nullptr) {
823 TELEPHONY_LOGE("MultiSimController::SetShowName get Data Base failed");
824 return TELEPHONY_ERR_LOCAL_PTR_NULL;
825 }
826 std::lock_guard<std::mutex> lock(mutex_);
827 NativeRdb::ValuesBucket values;
828 values.PutString(SimRdbInfo::SHOW_NAME, Str16ToStr8(name));
829 int32_t result = simDbHelper_->UpdateDataBySlotId(slotId, values);
830 if (result == INVALID_VALUE) {
831 TELEPHONY_LOGE("MultiSimController::SetShowName set Data Base failed");
832 return TELEPHONY_ERR_DATABASE_WRITE_FAIL;
833 }
834 localCacheInfo_[slotId].showName = Str16ToStr8(name); // save to cache
835 return TELEPHONY_ERR_SUCCESS;
836 }
837
GetIccId(int32_t slotId)838 std::u16string MultiSimController::GetIccId(int32_t slotId)
839 {
840 std::lock_guard<std::mutex> lock(mutex_);
841 if (static_cast<uint32_t>(slotId) >= localCacheInfo_.size()) {
842 TELEPHONY_LOGE("MultiSimController::GetIccId failed by nullptr");
843 return u"";
844 }
845 return Str8ToStr16(localCacheInfo_[slotId].iccId);
846 }
847
SetIccId(int32_t slotId,std::u16string iccId)848 bool MultiSimController::SetIccId(int32_t slotId, std::u16string iccId)
849 {
850 std::lock_guard<std::mutex> lock(mutex_);
851 if (static_cast<uint32_t>(slotId) >= localCacheInfo_.size()) {
852 TELEPHONY_LOGE("MultiSimController::SetIccId failed by out of range");
853 return false;
854 }
855 if (simDbHelper_ == nullptr) {
856 TELEPHONY_LOGE("MultiSimController::SetIccId failed by nullptr");
857 return false;
858 }
859 NativeRdb::ValuesBucket values;
860 values.PutString(SimRdbInfo::ICC_ID, Str16ToStr8(iccId));
861 values.PutString(SimRdbInfo::CARD_ID, Str16ToStr8(iccId)); // iccId == cardId by now
862 int32_t result = simDbHelper_->UpdateDataBySlotId(slotId, values);
863 if (result == INVALID_VALUE) {
864 TELEPHONY_LOGE("MultiSimController::SetIccId set Data Base failed");
865 return false;
866 }
867 localCacheInfo_[slotId].iccId = Str16ToStr8(iccId); // save to cache
868 localCacheInfo_[slotId].cardId = Str16ToStr8(iccId);
869 return true;
870 }
871
AnnounceDefaultVoiceSlotIdChanged(int32_t slotId)872 bool MultiSimController::AnnounceDefaultVoiceSlotIdChanged(int32_t slotId)
873 {
874 AAFwk::Want want;
875 want.SetParam(PARAM_SLOTID, slotId);
876 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_CARD_DEFAULT_VOICE_SUBSCRIPTION_CHANGED);
877 int32_t eventCode = EVENT_CODE;
878 std::string eventData(DEFAULT_VOICE_SLOT_CHANGED);
879 return PublishSimFileEvent(want, eventCode, eventData);
880 }
881
AnnounceDefaultSmsSlotIdChanged(int32_t slotId)882 bool MultiSimController::AnnounceDefaultSmsSlotIdChanged(int32_t slotId)
883 {
884 AAFwk::Want want;
885 want.SetParam(PARAM_SLOTID, slotId);
886 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_CARD_DEFAULT_SMS_SUBSCRIPTION_CHANGED);
887 int32_t eventCode = EVENT_CODE;
888 std::string eventData(DEFAULT_SMS_SLOT_CHANGED);
889 return PublishSimFileEvent(want, eventCode, eventData);
890 }
891
AnnounceDefaultCellularDataSlotIdChanged(int32_t slotId)892 bool MultiSimController::AnnounceDefaultCellularDataSlotIdChanged(int32_t slotId)
893 {
894 AAFwk::Want want;
895 want.SetParam(PARAM_SLOTID, slotId);
896 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_CARD_DEFAULT_DATA_SUBSCRIPTION_CHANGED);
897 int32_t eventCode = EVENT_CODE;
898 std::string eventData(DEFAULT_CELLULAR_DATA_SLOT_CHANGED);
899 return PublishSimFileEvent(want, eventCode, eventData);
900 }
901
AnnounceDefaultMainSlotIdChanged(int32_t slotId)902 bool MultiSimController::AnnounceDefaultMainSlotIdChanged(int32_t slotId)
903 {
904 AAFwk::Want want;
905 want.SetParam(PARAM_SLOTID, slotId);
906 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_CARD_DEFAULT_MAIN_SUBSCRIPTION_CHANGED);
907 int32_t eventCode = EVENT_CODE;
908 std::string eventData(DEFAULT_MAIN_SLOT_CHANGED);
909 return PublishSimFileEvent(want, eventCode, eventData);
910 }
911
PublishSimFileEvent(const AAFwk::Want & want,int eventCode,const std::string & eventData)912 bool MultiSimController::PublishSimFileEvent(const AAFwk::Want &want, int eventCode, const std::string &eventData)
913 {
914 EventFwk::CommonEventData data;
915 data.SetWant(want);
916 data.SetCode(eventCode);
917 data.SetData(eventData);
918 EventFwk::CommonEventPublishInfo publishInfo;
919 publishInfo.SetOrdered(true);
920 bool publishResult = EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
921 TELEPHONY_LOGI("MultiSimController::PublishSimFileEvent end###publishResult = %{public}d\n", publishResult);
922 return publishResult;
923 }
924
SaveImsSwitch(int32_t slotId,int32_t imsSwitchValue)925 int32_t MultiSimController::SaveImsSwitch(int32_t slotId, int32_t imsSwitchValue)
926 {
927 if (static_cast<std::size_t>(slotId) >= localCacheInfo_.size() || simDbHelper_ == nullptr) {
928 TELEPHONY_LOGE(
929 "failed by out of range or simDbHelper is nullptr, slotId = %{public}d localCacheInfo size = %{public}zu",
930 slotId, localCacheInfo_.size());
931 return TELEPHONY_ERROR;
932 }
933 NativeRdb::ValuesBucket values;
934 values.PutInt(SimRdbInfo::IMS_SWITCH, imsSwitchValue);
935 return simDbHelper_->UpdateDataByIccId(localCacheInfo_[slotId].iccId, values);
936 }
937
QueryImsSwitch(int32_t slotId,int32_t & imsSwitchValue)938 int32_t MultiSimController::QueryImsSwitch(int32_t slotId, int32_t &imsSwitchValue)
939 {
940 if (static_cast<std::size_t>(slotId) >= localCacheInfo_.size() || simDbHelper_ == nullptr) {
941 TELEPHONY_LOGE(
942 "failed by out of range or simDbHelper is nullptr, slotId = %{public}d localCacheInfo size = %{public}zu",
943 slotId, localCacheInfo_.size());
944 imsSwitchValue = IMS_SWITCH_VALUE_UNKNOWN;
945 return TELEPHONY_ERROR;
946 }
947 SimRdbInfo simRdbInfo;
948 simDbHelper_->QueryDataByIccId(localCacheInfo_[slotId].iccId, simRdbInfo);
949 imsSwitchValue = simRdbInfo.imsSwitch;
950 return TELEPHONY_SUCCESS;
951 }
952
GetActiveSimAccountInfoList(std::vector<IccAccountInfo> & iccAccountInfoList)953 int32_t MultiSimController::GetActiveSimAccountInfoList(std::vector<IccAccountInfo> &iccAccountInfoList)
954 {
955 if (!RefreshActiveIccAccountInfoList()) {
956 TELEPHONY_LOGE("MultiSimController::GetActiveSimAccountInfoList refresh failed");
957 return TELEPHONY_ERR_NO_SIM_CARD;
958 }
959 iccAccountInfoList.clear();
960 std::vector<IccAccountInfo>::iterator it = iccAccountInfoList_.begin();
961 while (it != iccAccountInfoList_.end()) {
962 TELEPHONY_LOGI("MultiSimController::GetActiveSimAccountInfoList slotIndex=%{public}d", it->slotIndex);
963 iccAccountInfoList.emplace_back(*it);
964 ++it;
965 }
966 return iccAccountInfoList.size() > 0 ? TELEPHONY_ERR_SUCCESS : TELEPHONY_ERR_NO_SIM_CARD;
967 }
968
GetRadioProtocolTech(int32_t slotId)969 int32_t MultiSimController::GetRadioProtocolTech(int32_t slotId)
970 {
971 if (radioProtocolController_ == nullptr) {
972 TELEPHONY_LOGE("radioProtocolController_ is nullptr");
973 return static_cast<int32_t>(RadioProtocolTech::RADIO_PROTOCOL_TECH_UNKNOWN);
974 }
975 return radioProtocolController_->GetRadioProtocolTech(slotId);
976 }
977
GetRadioProtocol(int32_t slotId)978 void MultiSimController::GetRadioProtocol(int32_t slotId)
979 {
980 if (radioProtocolController_ == nullptr) {
981 TELEPHONY_LOGE("radioProtocolController_ is nullptr");
982 return;
983 }
984 radioProtocolController_->GetRadioProtocol(slotId);
985 }
986 } // namespace Telephony
987 } // namespace OHOS
988