1 /*
2 * Copyright (C) 2021-2024 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 "sim_state_handle.h"
17
18 #include "common_event.h"
19 #include "common_event_manager.h"
20 #include "common_event_support.h"
21 #include "core_service_hisysevent.h"
22 #include "enum_convert.h"
23 #include "hilog/log.h"
24 #include "if_system_ability_manager.h"
25 #include "inner_event.h"
26 #include "iservice_registry.h"
27 #include "radio_event.h"
28 #include "satellite_service_client.h"
29 #include "sim_constant.h"
30 #include "sim_state_manager.h"
31 #include "system_ability_definition.h"
32 #include "tel_event_handler.h"
33 #include "tel_ril_sim_parcel.h"
34 #include "telephony_log_wrapper.h"
35 #include "telephony_state_registry_client.h"
36 #include "telephony_types.h"
37
38 using namespace OHOS::EventFwk;
39 namespace OHOS {
40 namespace Telephony {
41 const std::map<uint32_t, SimStateHandle::Func> SimStateHandle::memberFuncMap_ = {
42 { MSG_SIM_UNLOCK_PIN_DONE,
__anon8d8f95210102() 43 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
44 handle->GetUnlockResult(slotId, event);
45 } },
46 { MSG_SIM_UNLOCK_PUK_DONE,
__anon8d8f95210202() 47 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
48 handle->GetUnlockResult(slotId, event);
49 } },
50 { MSG_SIM_CHANGE_PIN_DONE,
__anon8d8f95210302() 51 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
52 handle->GetUnlockResult(slotId, event);
53 } },
54 { MSG_SIM_UNLOCK_PIN2_DONE,
__anon8d8f95210402() 55 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
56 handle->GetUnlockResult(slotId, event);
57 } },
58 { MSG_SIM_UNLOCK_PUK2_DONE,
__anon8d8f95210502() 59 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
60 handle->GetUnlockResult(slotId, event);
61 } },
62 { MSG_SIM_CHANGE_PIN2_DONE,
__anon8d8f95210602() 63 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
64 handle->GetUnlockResult(slotId, event);
65 } },
66 { MSG_SIM_UNLOCK_SIMLOCK_DONE,
__anon8d8f95210702() 67 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
68 handle->GetUnlockSimLockResult(slotId, event);
69 } },
70 { MSG_SIM_ENABLE_PIN_DONE,
__anon8d8f95210802() 71 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
72 handle->GetSetLockResult(slotId, event);
73 } },
74 { MSG_SIM_CHECK_PIN_DONE,
__anon8d8f95210902() 75 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
76 handle->GetSimLockState(slotId, event);
77 } },
78 { MSG_SIM_GET_REALTIME_ICC_STATUS_DONE,
__anon8d8f95210a02() 79 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
80 handle->GetSimCardData(slotId, event);
81 } },
82 { MSG_SIM_AUTHENTICATION_DONE,
__anon8d8f95210b02() 83 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
84 handle->GetSimAuthenticationResult(slotId, event);
85 } },
86 { MSG_SIM_SEND_NCFG_OPER_INFO_DONE,
__anon8d8f95210c02() 87 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
88 handle->GetSendSimMatchedOperatorInfoResult(slotId, event);
89 } },
90 { MSG_SIM_GET_SIM_IO_DONE,
__anon8d8f95210d02() 91 [](SimStateHandle *handle, int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event) {
92 handle->GetSimIOResult(slotId, event);
93 } },
94 };
95
SimStateHandle(const std::weak_ptr<SimStateManager> & simStateManager)96 SimStateHandle::SimStateHandle(const std::weak_ptr<SimStateManager> &simStateManager)
97 : TelEventHandler("SimStateHandle"), simStateManager_(simStateManager)
98 {
99 TELEPHONY_LOGI("SimStateHandle::SimStateHandle()");
100 }
101
Init(int32_t slotId)102 void SimStateHandle::Init(int32_t slotId)
103 {
104 slotId_ = slotId;
105 TELEPHONY_LOGI("SimStateHandle::HasSimCard(), slotId_ = %{public}d", slotId_);
106 ConnectService();
107 if (IsSatelliteSupported() == static_cast<int32_t>(SatelliteValue::SATELLITE_SUPPORTED)) {
108 std::shared_ptr<SatelliteServiceClient> satelliteClient =
109 DelayedSingleton<SatelliteServiceClient>::GetInstance();
110 satelliteClient->AddSimHandler(slotId_, std::static_pointer_cast<TelEventHandler>(shared_from_this()));
111 }
112 auto telRilManager = telRilManager_.lock();
113 if (telRilManager != nullptr) {
114 TELEPHONY_LOGI("SimStateHandle::SimStateHandle RegisterEvent start");
115 telRilManager->RegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_SIM_STATE_CHANGE, nullptr);
116 telRilManager->RegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_STATE_CHANGED, nullptr);
117 } else {
118 TELEPHONY_LOGE("SimStateHandle::SimStateHandle get ril_Manager fail");
119 return;
120 }
121 observerHandler_ = std::make_unique<ObserverHandler>();
122 if (observerHandler_ == nullptr) {
123 TELEPHONY_LOGE("SimStateHandle::failed to create new ObserverHandler");
124 return;
125 }
126 externalState_ = SimState::SIM_STATE_UNKNOWN;
127 CoreServiceHiSysEvent::WriteSimStateBehaviorEvent(slotId, static_cast<int32_t>(externalState_));
128 externalType_ = CardType::UNKNOWN_CARD;
129 }
130
IsSatelliteSupported()131 int32_t SimStateHandle::IsSatelliteSupported()
132 {
133 char satelliteSupported[SYSPARA_SIZE] = { 0 };
134 GetParameter(TEL_SATELLITE_SUPPORTED, SATELLITE_DEFAULT_VALUE, satelliteSupported, SYSPARA_SIZE);
135 TELEPHONY_LOGI("satelliteSupported is %{public}s", satelliteSupported);
136 return std::atoi(satelliteSupported);
137 }
138
HasSimCard()139 bool SimStateHandle::HasSimCard()
140 {
141 bool has = false;
142 if (iccState_.simStatus_ != ICC_CARD_ABSENT) {
143 has = true;
144 }
145 TELEPHONY_LOGD("SimStateHandle::HasSimCard(), has = %{public}d", has);
146 return has;
147 }
148
GetSimState()149 SimState SimStateHandle::GetSimState()
150 {
151 return externalState_;
152 }
153
GetCardType()154 CardType SimStateHandle::GetCardType()
155 {
156 TELEPHONY_LOGD("SimStateHandle::GetCardType() externalType_=%{public}d", static_cast<int32_t>(externalType_));
157 return externalType_;
158 }
159
GetIccid()160 std::string SimStateHandle::GetIccid()
161 {
162 return iccid_;
163 }
164
UnlockPin(int32_t slotId,const std::string & pin)165 void SimStateHandle::UnlockPin(int32_t slotId, const std::string &pin)
166 {
167 TELEPHONY_LOGI("SimStateHandle::UnlockPin1() slotId = %{public}d", slotId);
168 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_UNLOCK_PIN_DONE);
169 if (event == nullptr) {
170 TELEPHONY_LOGE("event is nullptr!");
171 return;
172 }
173 event->SetOwner(shared_from_this());
174 auto telRilManager = telRilManager_.lock();
175 if (telRilManager == nullptr) {
176 TELEPHONY_LOGE("telRilManager is nullptr!");
177 return;
178 }
179 telRilManager->UnlockPin(slotId, pin, event);
180 }
181
UnlockPuk(int32_t slotId,const std::string & newPin,const std::string & puk)182 void SimStateHandle::UnlockPuk(int32_t slotId, const std::string &newPin, const std::string &puk)
183 {
184 TELEPHONY_LOGI("SimStateHandle::UnlockPuk1() slotId = %{public}d", slotId);
185 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_UNLOCK_PUK_DONE);
186 if (event == nullptr) {
187 TELEPHONY_LOGE("event is nullptr!");
188 return;
189 }
190 event->SetOwner(shared_from_this());
191 auto telRilManager = telRilManager_.lock();
192 if (telRilManager == nullptr) {
193 TELEPHONY_LOGE("telRilManager is nullptr!");
194 return;
195 }
196 telRilManager->UnlockPuk(slotId, puk, newPin, event);
197 }
198
AlterPin(int32_t slotId,const std::string & newPin,const std::string & oldPin)199 void SimStateHandle::AlterPin(int32_t slotId, const std::string &newPin, const std::string &oldPin)
200 {
201 TELEPHONY_LOGI("SimStateHandle::AlterPin() slotId = %{public}d", slotId);
202 int32_t length = (int32_t)newPin.size();
203 SimPasswordParam simPinPassword;
204 simPinPassword.passwordLength = length;
205 simPinPassword.fac = FAC_PIN_LOCK;
206 simPinPassword.oldPassword = oldPin;
207 simPinPassword.newPassword = newPin;
208 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_CHANGE_PIN_DONE);
209 if (event == nullptr) {
210 TELEPHONY_LOGE("event is nullptr!");
211 return;
212 }
213 event->SetOwner(shared_from_this());
214 auto telRilManager = telRilManager_.lock();
215 if (telRilManager == nullptr) {
216 TELEPHONY_LOGE("telRilManager is nullptr!");
217 return;
218 }
219 telRilManager->ChangeSimPassword(slotId, simPinPassword, event);
220 }
221
UnlockPin2(int32_t slotId,const std::string & pin2)222 void SimStateHandle::UnlockPin2(int32_t slotId, const std::string &pin2)
223 {
224 TELEPHONY_LOGI("SimStateHandle::UnlockPin2() slotId = %{public}d", slotId);
225 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_UNLOCK_PIN2_DONE);
226 if (event == nullptr) {
227 TELEPHONY_LOGE("event is nullptr!");
228 return;
229 }
230 event->SetOwner(shared_from_this());
231 auto telRilManager = telRilManager_.lock();
232 if (telRilManager == nullptr) {
233 TELEPHONY_LOGE("telRilManager is nullptr!");
234 return;
235 }
236 telRilManager->UnlockPin2(slotId, pin2, event);
237 }
238
UnlockPuk2(int32_t slotId,const std::string & newPin2,const std::string & puk2)239 void SimStateHandle::UnlockPuk2(int32_t slotId, const std::string &newPin2, const std::string &puk2)
240 {
241 TELEPHONY_LOGI("SimStateHandle::UnlockPuk2() slotId = %{public}d", slotId);
242 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_UNLOCK_PUK2_DONE);
243 if (event == nullptr) {
244 TELEPHONY_LOGE("event is nullptr!");
245 return;
246 }
247 event->SetOwner(shared_from_this());
248 auto telRilManager = telRilManager_.lock();
249 if (telRilManager == nullptr) {
250 TELEPHONY_LOGE("telRilManager is nullptr!");
251 return;
252 }
253 telRilManager->UnlockPuk2(slotId, puk2, newPin2, event);
254 }
255
AlterPin2(int32_t slotId,const std::string & newPin2,const std::string & oldPin2)256 void SimStateHandle::AlterPin2(int32_t slotId, const std::string &newPin2, const std::string &oldPin2)
257 {
258 TELEPHONY_LOGI("SimStateHandle::AlterPin2() slotId = %{public}d", slotId);
259 int32_t length = (int32_t)newPin2.size();
260 SimPasswordParam simPin2Password;
261 simPin2Password.passwordLength = length;
262 simPin2Password.fac = FDN_PIN_LOCK;
263 simPin2Password.oldPassword = oldPin2;
264 simPin2Password.newPassword = newPin2;
265 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_CHANGE_PIN2_DONE);
266 if (event == nullptr) {
267 TELEPHONY_LOGE("event is nullptr!");
268 return;
269 }
270 event->SetOwner(shared_from_this());
271 auto telRilManager = telRilManager_.lock();
272 if (telRilManager == nullptr) {
273 TELEPHONY_LOGE("telRilManager is nullptr!");
274 return;
275 }
276 telRilManager->ChangeSimPassword(slotId, simPin2Password, event);
277 }
278
SetLockState(int32_t slotId,const LockInfo & options)279 void SimStateHandle::SetLockState(int32_t slotId, const LockInfo &options)
280 {
281 TELEPHONY_LOGI("SimStateHandle::SetLockState() slotId = %{public}d", slotId);
282 SimLockParam simLock;
283 simLock.mode = static_cast<int32_t>(options.lockState);
284 simLock.passwd = Str16ToStr8(options.password);
285 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_ENABLE_PIN_DONE);
286 if (event == nullptr) {
287 TELEPHONY_LOGE("event is nullptr!");
288 return;
289 }
290 event->SetOwner(shared_from_this());
291 if (LockType::PIN_LOCK == options.lockType) {
292 simLock.fac = FAC_PIN_LOCK;
293 } else {
294 simLock.fac = FDN_PIN2_LOCK;
295 }
296 auto telRilManager = telRilManager_.lock();
297 if (telRilManager == nullptr) {
298 TELEPHONY_LOGE("telRilManager is nullptr!");
299 return;
300 }
301 telRilManager->SetSimLock(slotId, simLock, event);
302 }
303
UnlockSimLock(int32_t slotId,const PersoLockInfo & lockInfo)304 void SimStateHandle::UnlockSimLock(int32_t slotId, const PersoLockInfo &lockInfo)
305 {
306 TELEPHONY_LOGI("SimStateHandle::UnlockSimLock() slotId = %{public}d", slotId);
307 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_UNLOCK_SIMLOCK_DONE);
308 if (event == nullptr) {
309 TELEPHONY_LOGE("event is nullptr!");
310 return;
311 }
312 event->SetOwner(shared_from_this());
313 auto telRilManager = telRilManager_.lock();
314 if (telRilManager == nullptr) {
315 TELEPHONY_LOGE("SimStateHandle telRilManager is nullptr!!");
316 return;
317 }
318 int32_t lockType = static_cast<int32_t>(lockInfo.lockType);
319 telRilManager->UnlockSimLock(slotId, lockType, Str16ToStr8(lockInfo.password), event);
320 }
321
SetRilManager(std::weak_ptr<Telephony::ITelRilManager> telRilManager)322 void SimStateHandle::SetRilManager(std::weak_ptr<Telephony::ITelRilManager> telRilManager)
323 {
324 telRilManager_ = telRilManager;
325 auto telRilManagerNew = telRilManager_.lock();
326 if (telRilManagerNew == nullptr) {
327 TELEPHONY_LOGE("SimStateHandle set NULL TelRilManager!!");
328 }
329 }
330
GetLockState(int32_t slotId,LockType lockType)331 void SimStateHandle::GetLockState(int32_t slotId, LockType lockType)
332 {
333 TELEPHONY_LOGI("SimStateHandle::GetLockState() slotId = %{public}d", slotId);
334 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_CHECK_PIN_DONE);
335 if (event == nullptr) {
336 TELEPHONY_LOGE("event is nullptr!");
337 return;
338 }
339 event->SetOwner(shared_from_this());
340 auto telRilManager = telRilManager_.lock();
341 if (telRilManager == nullptr) {
342 TELEPHONY_LOGE("telRilManager is nullptr!");
343 return;
344 }
345 if (LockType::PIN_LOCK == lockType) {
346 telRilManager->GetSimLockStatus(slotId, FAC_PIN_LOCK, event);
347 } else {
348 telRilManager->GetSimLockStatus(slotId, FDN_PIN2_LOCK, event);
349 }
350 }
351
ProcessIccCardState(IccState & ar,int32_t slotId)352 void SimStateHandle::ProcessIccCardState(IccState &ar, int32_t slotId)
353 {
354 TELEPHONY_LOGI("SimStateHandle::ProcessIccCardState slotId = %{public}d", slotId);
355 LockReason reason = LockReason::SIM_NONE;
356 const int32_t newSimType = ar.simType_;
357 const int32_t newSimStatus = ar.simStatus_;
358 iccState_ = ar;
359 auto iter = simIccStatusMap_.find(newSimStatus);
360 TELEPHONY_LOGI("SimStateHandle::ProcessIccCardState SimType[%{public}d], SimStatus[%{public}s](%{public}d)",
361 newSimType, iter->second.c_str(), newSimStatus);
362 if (oldSimType_ != newSimType) {
363 CardTypeEscape(newSimType, slotId);
364 oldSimType_ = newSimType;
365 }
366 if (oldSimStatus_ != newSimStatus) {
367 iccid_ = ar.iccid_;
368 SimStateEscape(newSimStatus, slotId, reason);
369 oldSimStatus_ = newSimStatus;
370 iter = simIccStatusMap_.find(newSimStatus);
371 TELEPHONY_LOGI("will to NotifyIccStateChanged at newSimStatus[%{public}s]"
372 "(%{public}d) observerHandler_ is nullptr[%{public}d] ",
373 iter->second.c_str(), newSimStatus, (observerHandler_ == nullptr));
374 if (observerHandler_ != nullptr) {
375 observerHandler_->NotifyObserver(RadioEvent::RADIO_SIM_STATE_CHANGE, slotId);
376 observerHandler_->NotifyObserver(RadioEvent::RADIO_SIM_ICCID_LOADED, slotId);
377 }
378 DelayedRefSingleton<TelephonyStateRegistryClient>::GetInstance().UpdateSimState(
379 slotId, externalType_, externalState_, reason);
380 }
381 }
382
UnInit()383 void SimStateHandle::UnInit()
384 {
385 auto telRilManager = telRilManager_.lock();
386 if (telRilManager != nullptr) {
387 telRilManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_SIM_STATE_CHANGE);
388 telRilManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_STATE_CHANGED);
389 }
390 if (IsSatelliteSupported() == static_cast<int32_t>(SatelliteValue::SATELLITE_SUPPORTED) &&
391 satelliteCallback_ != nullptr) {
392 std::shared_ptr<SatelliteServiceClient> satelliteClient =
393 DelayedSingleton<SatelliteServiceClient>::GetInstance();
394 satelliteClient->UnRegisterCoreNotify(slotId_, RadioEvent::RADIO_SIM_STATE_CHANGE);
395 }
396 }
397
RegisterSatelliteCallback()398 void SimStateHandle::RegisterSatelliteCallback()
399 {
400 satelliteCallback_ =
401 std::make_unique<SatelliteCoreCallback>(std::static_pointer_cast<TelEventHandler>(shared_from_this()))
402 .release();
403 std::shared_ptr<SatelliteServiceClient> satelliteClient = DelayedSingleton<SatelliteServiceClient>::GetInstance();
404 satelliteClient->RegisterCoreNotify(slotId_, RadioEvent::RADIO_SIM_STATE_CHANGE, satelliteCallback_);
405 }
406
UnregisterSatelliteCallback()407 void SimStateHandle::UnregisterSatelliteCallback()
408 {
409 if (IsSatelliteSupported() == static_cast<int32_t>(SatelliteValue::SATELLITE_SUPPORTED)) {
410 satelliteCallback_ = nullptr;
411 }
412 }
413
ObtainIccStatus(int32_t slotId)414 void SimStateHandle::ObtainIccStatus(int32_t slotId)
415 {
416 TELEPHONY_LOGI("SimStateHandle::ObtainIccStatus() slotId = %{public}d", slotId);
417 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_GET_ICC_STATUS_DONE);
418 if (event == nullptr) {
419 TELEPHONY_LOGE("event is nullptr!");
420 return;
421 }
422 event->SetOwner(shared_from_this());
423 auto telRilManager = telRilManager_.lock();
424 if (telRilManager == nullptr) {
425 TELEPHONY_LOGE("telRilManager is nullptr!");
426 return;
427 }
428 telRilManager->GetSimStatus(slotId, event); // get sim card state
429 }
430
ObtainRealtimeIccStatus(int32_t slotId)431 void SimStateHandle::ObtainRealtimeIccStatus(int32_t slotId)
432 {
433 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_GET_REALTIME_ICC_STATUS_DONE);
434 if (event == nullptr) {
435 TELEPHONY_LOGE("event is nullptr!");
436 return;
437 }
438 event->SetOwner(shared_from_this());
439 auto telRilManager = telRilManager_.lock();
440 if (telRilManager == nullptr) {
441 TELEPHONY_LOGE("telRilManager is nullptr!");
442 return;
443 }
444 telRilManager->GetSimStatus(slotId, event); // get sim card state
445 }
446
SimAuthentication(int32_t slotId,AuthType authType,const std::string & authData)447 int32_t SimStateHandle::SimAuthentication(int32_t slotId, AuthType authType, const std::string &authData)
448 {
449 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_AUTHENTICATION_DONE);
450 if (event == nullptr) {
451 TELEPHONY_LOGE("event is nullptr!");
452 return SIM_AUTH_FAIL;
453 }
454 event->SetOwner(shared_from_this());
455 SimAuthenticationRequestInfo requireInfo;
456 requireInfo.serial = static_cast<int32_t>(authType);
457 requireInfo.aid = GetAidByCardType(externalType_);
458 requireInfo.authData = authData;
459 auto telRilManager = telRilManager_.lock();
460 if (telRilManager == nullptr) {
461 TELEPHONY_LOGE("SimStateHandle::SimAuthentication() telRilManager is nullptr!!");
462 return SIM_AUTH_FAIL;
463 }
464 return telRilManager->SimAuthentication(slotId, requireInfo, event);
465 }
466
SendSimMatchedOperatorInfo(int32_t slotId,int32_t state,const std::string & operName,const std::string & operKey)467 void SimStateHandle::SendSimMatchedOperatorInfo(
468 int32_t slotId, int32_t state, const std::string &operName, const std::string &operKey)
469 {
470 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_SEND_NCFG_OPER_INFO_DONE);
471 if (event == nullptr) {
472 TELEPHONY_LOGE("event is nullptr!");
473 return;
474 }
475 event->SetOwner(shared_from_this());
476 NcfgOperatorInfo requireInfo;
477 requireInfo.state = state;
478 requireInfo.operName = operName;
479 requireInfo.operKey = operKey;
480 auto telRilManager = telRilManager_.lock();
481 if (telRilManager == nullptr) {
482 TELEPHONY_LOGE("SimStateHandle::SendSimMatchedOperatorInfo() telRilManager is nullptr!!");
483 return;
484 }
485 telRilManager->SendSimMatchedOperatorInfo(slotId, requireInfo, event);
486 }
487
GetAidByCardType(CardType type)488 std::string SimStateHandle::GetAidByCardType(CardType type)
489 {
490 switch (type) {
491 case CardType::SINGLE_MODE_RUIM_CARD:
492 return CDMA_FAKE_AID;
493 case CardType::SINGLE_MODE_SIM_CARD:
494 [[fallthrough]]; // fall_through
495 case CardType::DUAL_MODE_CG_CARD:
496 [[fallthrough]]; // fall_through
497 case CardType::CT_NATIONAL_ROAMING_CARD:
498 [[fallthrough]]; // fall_through
499 case CardType::CU_DUAL_MODE_CARD:
500 [[fallthrough]]; // fall_through
501 case CardType::DUAL_MODE_TELECOM_LTE_CARD:
502 [[fallthrough]]; // fall_through
503 case CardType::DUAL_MODE_UG_CARD:
504 return GSM_FAKE_AID;
505 default:
506 break;
507 }
508 return USIM_AID;
509 }
510
GetSimCardData(int32_t slotId,const AppExecFwk::InnerEvent::Pointer & event)511 void SimStateHandle::GetSimCardData(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event)
512 {
513 TELEPHONY_LOGD("SimStateHandle::GetSimCardData slotId = %{public}d", slotId);
514 int32_t error = 0;
515 IccState iccState;
516 std::shared_ptr<SimCardStatusInfo> param = event->GetSharedObject<SimCardStatusInfo>();
517 std::shared_ptr<RadioResponseInfo> response = event->GetSharedObject<RadioResponseInfo>();
518 if ((param == nullptr) && (response == nullptr)) {
519 TELEPHONY_LOGE("SimStateHandle::GetSimCardData() fail");
520 return;
521 }
522 if (param != nullptr) {
523 iccState.simType_ = param->simType;
524 iccState.simStatus_ = param->simState;
525 iccState.iccid_ = param->iccid;
526 modemInitDone_ = true;
527 TELEPHONY_LOGI("SimStateHandle::GetSimCardData(), slot%{public}d, type = %{public}d, status = %{public}d",
528 slotId, iccState.simType_, iccState.simStatus_);
529 } else {
530 error = static_cast<int32_t>(response->error);
531 TELEPHONY_LOGI("SimStateHandle::GetSimCardData(), slot%{public}d, error = %{public}d", slotId, error);
532 return;
533 }
534 ProcessIccCardState(iccState, slotId);
535 }
536
GetSimLockState(int32_t slotId,const AppExecFwk::InnerEvent::Pointer & event)537 void SimStateHandle::GetSimLockState(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event)
538 {
539 TELEPHONY_LOGI("SimStateHandle::GetSimLockState slotId = %{public}d", slotId);
540 int32_t error = 0;
541 std::shared_ptr<int32_t> param = event->GetSharedObject<int32_t>();
542 std::shared_ptr<RadioResponseInfo> response = event->GetSharedObject<RadioResponseInfo>();
543 if ((param == nullptr) && (response == nullptr)) {
544 TELEPHONY_LOGE("SimStateHandle::GetSimLockState() fail");
545 return;
546 }
547 if (param != nullptr) {
548 TELEPHONY_LOGI("SimStateHandle::GetSimLockState(), param = %{public}d", *param);
549 unlockRespon_.lockState = *param;
550 } else {
551 unlockRespon_.lockState = static_cast<int32_t>(LockState::LOCK_ERROR);
552 error = static_cast<int32_t>(response->error);
553 TELEPHONY_LOGI("SimStateHandle::GetSimLockState(), error = %{public}d", error);
554 }
555 TELEPHONY_LOGI("SimStateHandle::GetSimLockState(), lockState = %{public}d", unlockRespon_.lockState);
556 }
557
GetSetLockResult(int32_t slotId,const AppExecFwk::InnerEvent::Pointer & event)558 void SimStateHandle::GetSetLockResult(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event)
559 {
560 TELEPHONY_LOGI("SimStateHandle::GetSetLockResult slotId = %{public}d", slotId);
561 std::shared_ptr<LockStatusResp> param = event->GetSharedObject<LockStatusResp>();
562 std::shared_ptr<RadioResponseInfo> response = event->GetSharedObject<RadioResponseInfo>();
563 if ((param == nullptr) && (response == nullptr)) {
564 TELEPHONY_LOGE("SimStateHandle::GetSetLockResult() fail");
565 return;
566 }
567 if (param != nullptr) {
568 unlockRespon_.result = param->result;
569 unlockRespon_.remain = param->remain;
570 TELEPHONY_LOGI("SimStateHandle::GetSetLockResult result = %{public}d, remain = %{public}d",
571 unlockRespon_.result, unlockRespon_.remain);
572 } else {
573 unlockRespon_.result = static_cast<int32_t>(response->error);
574 }
575 TELEPHONY_LOGI("SimStateHandle::GetSetLockResult(), iccUnlockResponse = %{public}d", unlockRespon_.result);
576 }
577
GetUnlockResult(int32_t slotId,const AppExecFwk::InnerEvent::Pointer & event)578 void SimStateHandle::GetUnlockResult(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event)
579 {
580 TELEPHONY_LOGI("SimStateHandle::GetUnlockResult slotId = %{public}d", slotId);
581 std::shared_ptr<LockStatusResp> param = event->GetSharedObject<LockStatusResp>();
582 std::shared_ptr<RadioResponseInfo> response = event->GetSharedObject<RadioResponseInfo>();
583 if ((param == nullptr) && (response == nullptr)) {
584 TELEPHONY_LOGE("SimStateHandle::GetSimUnlockResult() fail");
585 return;
586 }
587 if (param != nullptr) {
588 unlockRespon_.result = param->result;
589 unlockRespon_.remain = param->remain;
590 TELEPHONY_LOGE("SimStateHandle::GetUnlockReult result:%{public}d, remain:%{public}d",
591 param->result, param->remain);
592 } else {
593 TELEPHONY_LOGE("SimStateHandle::GetUnlockResult param is null");
594 unlockRespon_.result = static_cast<int32_t>(response->error);
595 }
596 TELEPHONY_LOGI("SimStateHandle::GetSimUnlockResponse(), iccUnlockResponse = %{public}d", unlockRespon_.result);
597 }
598
GetUnlockSimLockResult(int32_t slotId,const AppExecFwk::InnerEvent::Pointer & event)599 void SimStateHandle::GetUnlockSimLockResult(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event)
600 {
601 TELEPHONY_LOGI("SimStateHandle::GetUnlockSimLockResult slotId = %{public}d", slotId);
602 std::shared_ptr<LockStatusResp> param = event->GetSharedObject<LockStatusResp>();
603 std::shared_ptr<RadioResponseInfo> response = event->GetSharedObject<RadioResponseInfo>();
604 if ((param == nullptr) && (response == nullptr)) {
605 TELEPHONY_LOGE("SimStateHandle::GetUnlockSimLockResult() fail");
606 return;
607 }
608 if (param != nullptr) {
609 TELEPHONY_LOGI("SimStateHandle::GetUnlockSimLockResult param is true");
610 simlockRespon_.result = param->result;
611 simlockRespon_.remain = param->remain;
612 } else {
613 TELEPHONY_LOGE("SimStateHandle::GetUnlockSimLockResult param is null");
614 simlockRespon_.result = static_cast<int32_t>(response->error);
615 }
616 }
617
GetSimAuthenticationResult(int32_t slotId,const AppExecFwk::InnerEvent::Pointer & event)618 void SimStateHandle::GetSimAuthenticationResult(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event)
619 {
620 TELEPHONY_LOGI("SimStateHandle::GetSimAuthenticationResult slotId = %{public}d", slotId);
621 auto response = event->GetSharedObject<IccIoResultInfo>();
622 if (response == nullptr) {
623 TELEPHONY_LOGE("SimStateHandle::GetSimAuthenticationResult() fail");
624 return;
625 }
626 simAuthRespon_.sw1 = response->sw1;
627 simAuthRespon_.sw2 = response->sw2;
628 simAuthRespon_.response = response->response;
629 }
630
GetSendSimMatchedOperatorInfoResult(int32_t slotId,const AppExecFwk::InnerEvent::Pointer & event)631 void SimStateHandle::GetSendSimMatchedOperatorInfoResult(
632 int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event)
633 {
634 TELEPHONY_LOGI("SimStateHandle::GetSendSimMatchedOperatorInfoResult slotId = %{public}d", slotId);
635 std::shared_ptr<RadioResponseInfo> response = event->GetSharedObject<RadioResponseInfo>();
636 if (response == nullptr) {
637 TELEPHONY_LOGE("SimStateHandle::GetSendSimMatchedOperatorInfoResult() fail");
638 return;
639 }
640 sendSimMatchedOperatorInfoResult_ = static_cast<int32_t>(response->error);
641 }
642
GetSimAuthenticationResponse()643 SimAuthenticationResponse SimStateHandle::GetSimAuthenticationResponse()
644 {
645 return simAuthRespon_;
646 }
647
GetSendSimMatchedOperatorInfoResponse()648 int32_t SimStateHandle::GetSendSimMatchedOperatorInfoResponse()
649 {
650 return sendSimMatchedOperatorInfoResult_;
651 }
652
GetUnlockData()653 UnlockData SimStateHandle::GetUnlockData()
654 {
655 return unlockRespon_;
656 }
657
GetSimlockResponse()658 LockStatusResponse SimStateHandle::GetSimlockResponse()
659 {
660 return simlockRespon_;
661 }
662
PublishSimStateEvent(std::string event,int32_t eventCode,std::string eventData)663 bool SimStateHandle::PublishSimStateEvent(std::string event, int32_t eventCode, std::string eventData)
664 {
665 AAFwk::Want want;
666 want.SetAction(event);
667 EventFwk::CommonEventData data;
668 data.SetWant(want);
669 data.SetCode(eventCode);
670 data.SetData(eventData);
671 EventFwk::CommonEventPublishInfo publishInfo;
672 publishInfo.SetOrdered(false);
673 publishInfo.SetSticky(true);
674 bool publishResult = CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
675 TELEPHONY_LOGI("SimStateHandle::PublishSimStateEvent result : %{public}d", publishResult);
676 return publishResult;
677 }
678
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)679 void SimStateHandle::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
680 {
681 if (event == nullptr) {
682 TELEPHONY_LOGE("event is nullptr!");
683 return;
684 }
685 uint32_t eventId = event->GetInnerEventId();
686 TELEPHONY_LOGD("SimStateHandle::ProcessEvent(), eventId = %{public}d, slotId_ = %{public}d", eventId, slotId_);
687 auto itFunc = memberFuncMap_.find(eventId);
688 if (itFunc != memberFuncMap_.end()) {
689 auto memberFunc = itFunc->second;
690 if (memberFunc != nullptr) {
691 memberFunc(this, slotId_, event);
692 }
693 auto simStateManager = simStateManager_.lock();
694 if (simStateManager == nullptr) {
695 TELEPHONY_LOGE("simStateManager nullptr");
696 return;
697 }
698 simStateManager->SyncCmdResponse();
699 return;
700 }
701
702 switch (eventId) {
703 case RadioEvent::RADIO_STATE_CHANGED:
704 if (IsRadioStateUnavailable(event)) {
705 break;
706 }
707 [[fallthrough]]; // fall_through
708 case RadioEvent::RADIO_SIM_STATE_CHANGE:
709 ObtainIccStatus(slotId_);
710 break;
711 case MSG_SIM_GET_ICC_STATUS_DONE:
712 GetSimCardData(slotId_, event);
713 break;
714 default:
715 TELEPHONY_LOGI("SimStateHandle::ProcessEvent(), unknown event");
716 break;
717 }
718 }
719
ConnectService()720 bool SimStateHandle::ConnectService()
721 {
722 auto systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
723 if (systemManager == nullptr) {
724 TELEPHONY_LOGE("SimStateHandle::ConnectService() GetSystemAbilityManager null");
725 return false;
726 }
727 sptr<IRemoteObject> object = systemManager->GetSystemAbility(TELEPHONY_STATE_REGISTRY_SYS_ABILITY_ID);
728 if (object == nullptr) {
729 TELEPHONY_LOGE("SimStateHandle::ConnectService faild");
730 return false;
731 }
732 TELEPHONY_LOGI("SimStateHandle::ConnectService success");
733 return true;
734 }
735
IsIccReady()736 bool SimStateHandle::IsIccReady()
737 {
738 return externalState_ == SimState::SIM_STATE_READY;
739 }
740
IsIccLocked()741 bool SimStateHandle::IsIccLocked()
742 {
743 return externalState_ == SimState::SIM_STATE_LOCKED;
744 }
745
SimStateEscape(int32_t simState,int slotId,LockReason & reason)746 void SimStateHandle::SimStateEscape(
747 int32_t simState, int slotId, LockReason &reason)
748 {
749 switch (simState) {
750 case ICC_CARD_ABSENT:
751 externalState_ = SimState::SIM_STATE_NOT_PRESENT;
752 PublishSimStateEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED, ICC_STATE_ABSENT, "");
753 break;
754 case ICC_CONTENT_READY:
755 externalState_ = SimState::SIM_STATE_READY;
756 observerHandler_->NotifyObserver(RadioEvent::RADIO_SIM_STATE_READY, slotId);
757 PublishSimStateEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED, ICC_STATE_READY, "");
758 break;
759 case ICC_CONTENT_PIN:
760 externalState_ = SimState::SIM_STATE_LOCKED;
761 reason = LockReason::SIM_PIN;
762 observerHandler_->NotifyObserver(RadioEvent::RADIO_SIM_STATE_LOCKED, slotId);
763 PublishSimStateEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED, ICC_STATE_PIN, "");
764 break;
765 case ICC_CONTENT_PUK:
766 externalState_ = SimState::SIM_STATE_LOCKED;
767 reason = LockReason::SIM_PUK;
768 observerHandler_->NotifyObserver(RadioEvent::RADIO_SIM_STATE_LOCKED, slotId);
769 PublishSimStateEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED, ICC_STATE_PUK, "");
770 break;
771 default:
772 SimLockStateEscape(simState, slotId, reason);
773 break;
774 }
775 CoreServiceHiSysEvent::WriteSimStateBehaviorEvent(slotId, static_cast<int32_t>(externalState_));
776 }
777
SimLockStateEscape(int32_t simState,int slotId,LockReason & reason)778 void SimStateHandle::SimLockStateEscape(
779 int32_t simState, int slotId, LockReason &reason)
780 {
781 bool isSimLockState = true;
782 switch (simState) {
783 case ICC_CONTENT_PH_NET_PIN:
784 reason = LockReason::SIM_PN_PIN;
785 break;
786 case ICC_CONTENT_PH_NET_PUK:
787 reason = LockReason::SIM_PN_PUK;
788 break;
789 case ICC_CONTENT_PH_NET_SUB_PIN:
790 reason = LockReason::SIM_PU_PIN;
791 break;
792 case ICC_CONTENT_PH_NET_SUB_PUK:
793 reason = LockReason::SIM_PU_PUK;
794 break;
795 case ICC_CONTENT_PH_SP_PIN:
796 reason = LockReason::SIM_PP_PIN;
797 break;
798 case ICC_CONTENT_PH_SP_PUK:
799 reason = LockReason::SIM_PP_PUK;
800 break;
801 case ICC_CONTENT_UNKNOWN:
802 [[fallthrough]]; // fall_through
803 default:
804 isSimLockState = false;
805 externalState_ = SimState::SIM_STATE_UNKNOWN;
806 CoreServiceHiSysEvent::WriteSimStateBehaviorEvent(slotId, static_cast<int32_t>(externalState_));
807 PublishSimStateEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED,
808 ICC_STATE_NOT_READY, "");
809 break;
810 }
811 if (isSimLockState) {
812 NotifySimLock(slotId);
813 }
814 }
815
NotifySimLock(int slotId)816 void SimStateHandle::NotifySimLock(int slotId)
817 {
818 externalState_ = SimState::SIM_STATE_LOCKED;
819 CoreServiceHiSysEvent::WriteSimStateBehaviorEvent(slotId, static_cast<int32_t>(externalState_));
820 observerHandler_->NotifyObserver(RadioEvent::RADIO_SIM_STATE_SIMLOCK);
821 PublishSimStateEvent(EventFwk::CommonEventSupport::COMMON_EVENT_SIM_STATE_CHANGED, ICC_STATE_SIMLOCK, "");
822 }
823
CardTypeEscape(int32_t simType,int slotId)824 void SimStateHandle::CardTypeEscape(int32_t simType, int slotId)
825 {
826 CardType cardTypeStorage = externalType_;
827 TELEPHONY_LOGI("SimStateHandle::CardTypeEscape() simType=%{public}d, slotId = %{public}d", simType, slotId);
828 switch (simType) {
829 case ICC_UNKNOWN_TYPE:
830 externalType_ = CardType::UNKNOWN_CARD;
831 break;
832 case ICC_SIM_TYPE:
833 externalType_ = CardType::SINGLE_MODE_SIM_CARD;
834 break;
835 case ICC_USIM_TYPE:
836 externalType_ = CardType::SINGLE_MODE_USIM_CARD;
837 break;
838 case ICC_RUIM_TYPE:
839 externalType_ = CardType::SINGLE_MODE_RUIM_CARD;
840 break;
841 case ICC_CG_TYPE:
842 externalType_ = CardType::DUAL_MODE_CG_CARD;
843 break;
844 case ICC_DUAL_MODE_ROAMING_TYPE:
845 externalType_ = CardType::CT_NATIONAL_ROAMING_CARD;
846 break;
847 case ICC_UNICOM_DUAL_MODE_TYPE:
848 externalType_ = CardType::CU_DUAL_MODE_CARD;
849 break;
850 case ICC_4G_LTE_TYPE:
851 externalType_ = CardType::DUAL_MODE_TELECOM_LTE_CARD;
852 break;
853 case ICC_UG_TYPE:
854 externalType_ = CardType::DUAL_MODE_UG_CARD;
855 break;
856 case ICC_IMS_TYPE:
857 externalType_ = CardType::SINGLE_MODE_ISIM_CARD;
858 break;
859 default:
860 externalType_ = CardType::UNKNOWN_CARD;
861 break;
862 }
863 if (externalType_ != cardTypeStorage) {
864 TELEPHONY_LOGI("will to NotifyIccCardTypeChange at oldSimType[%{public}d] != newSimType[%{public}d]",
865 cardTypeStorage, externalType_);
866 observerHandler_->NotifyObserver(RadioEvent::RADIO_CARD_TYPE_CHANGE);
867 } else {
868 TELEPHONY_LOGI("do not NotifyIccCardTypeChange at oldSimType[%{public}d] == newSimType[%{public}d]",
869 cardTypeStorage, externalType_);
870 }
871 }
872
RegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> & handler,int what)873 void SimStateHandle::RegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what)
874 {
875 switch (what) {
876 case RadioEvent::RADIO_SIM_STATE_CHANGE:
877 TELEPHONY_LOGI("SimStateHandle::RegisterIccStateChanged()");
878 observerHandler_->RegObserver(RadioEvent::RADIO_SIM_STATE_CHANGE, handler);
879 break;
880 case RadioEvent::RADIO_SIM_STATE_READY:
881 TELEPHONY_LOGI("SimStateHandle::RegisterIccReady()");
882 observerHandler_->RegObserver(RadioEvent::RADIO_SIM_STATE_READY, handler);
883 if (IsIccReady() && handler != nullptr) {
884 TelEventHandler::SendTelEvent(handler, RadioEvent::RADIO_SIM_STATE_READY, slotId_, 0);
885 TELEPHONY_LOGI("SimStateHandle::RegisterIccReady() OK send, slotId = %{public}d", slotId_);
886 }
887 break;
888 case RadioEvent::RADIO_SIM_STATE_LOCKED:
889 TELEPHONY_LOGI("SimStateHandle::RegisterIccLocked()");
890 observerHandler_->RegObserver(RadioEvent::RADIO_SIM_STATE_LOCKED, handler);
891 if (IsIccLocked() && handler != nullptr) {
892 TelEventHandler::SendTelEvent(handler, RadioEvent::RADIO_SIM_STATE_LOCKED, slotId_, 0);
893 TELEPHONY_LOGI("SimStateHandle::RegisterIccLocked() OK send, slotId = %{public}d", slotId_);
894 }
895 break;
896 case RadioEvent::RADIO_SIM_STATE_SIMLOCK:
897 TELEPHONY_LOGI("SimStateHandle::RegisterIccSimLock()");
898 observerHandler_->RegObserver(RadioEvent::RADIO_SIM_STATE_SIMLOCK, handler);
899 break;
900 case RadioEvent::RADIO_CARD_TYPE_CHANGE:
901 TELEPHONY_LOGI("SimStateHandle::RegisterCardTypeChange()");
902 observerHandler_->RegObserver(RadioEvent::RADIO_CARD_TYPE_CHANGE, handler);
903 break;
904 case RadioEvent::RADIO_SIM_ICCID_LOADED:
905 TELEPHONY_LOGI("SimStateHandle::RegisterIccidLoaded()");
906 observerHandler_->RegObserver(RadioEvent::RADIO_SIM_ICCID_LOADED, handler);
907 if (!iccid_.empty() && handler != nullptr) {
908 TelEventHandler::SendTelEvent(handler, RadioEvent::RADIO_SIM_ICCID_LOADED, slotId_, 0);
909 TELEPHONY_LOGI("SimStateHandle::RegisterIccidLoaded() OK send, slotId = %{public}d", slotId_);
910 }
911 break;
912 default:
913 TELEPHONY_LOGI("SimStateHandle RegisterCoreNotify do default");
914 break;
915 }
916 }
917
UnRegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> & handler,int what)918 void SimStateHandle::UnRegisterCoreNotify(const std::shared_ptr<AppExecFwk::EventHandler> &handler, int what)
919 {
920 switch (what) {
921 case RadioEvent::RADIO_SIM_STATE_CHANGE:
922 TELEPHONY_LOGI("SimStateHandle::UnregisterIccStateChanged()");
923 observerHandler_->Remove(RadioEvent::RADIO_SIM_STATE_CHANGE, handler);
924 break;
925 case RadioEvent::RADIO_SIM_STATE_READY:
926 TELEPHONY_LOGI("SimStateHandle::UnregisterIccReady()");
927 observerHandler_->Remove(RadioEvent::RADIO_SIM_STATE_READY, handler);
928 break;
929 case RadioEvent::RADIO_SIM_STATE_LOCKED:
930 TELEPHONY_LOGI("SimStateHandle::UnregisterIccLocked()");
931 observerHandler_->Remove(RadioEvent::RADIO_SIM_STATE_LOCKED, handler);
932 break;
933 case RadioEvent::RADIO_SIM_STATE_SIMLOCK:
934 TELEPHONY_LOGI("SimStateHandle::UnregisterIccSimLock()");
935 observerHandler_->Remove(RadioEvent::RADIO_SIM_STATE_SIMLOCK, handler);
936 break;
937 case RadioEvent::RADIO_CARD_TYPE_CHANGE:
938 TELEPHONY_LOGI("SimStateHandle::RegisterCardTypeChange()");
939 observerHandler_->Remove(RadioEvent::RADIO_CARD_TYPE_CHANGE, handler);
940 break;
941 default:
942 TELEPHONY_LOGI("SimStateHandle UnRegisterCoreNotify do default");
943 break;
944 }
945 }
946
IsRadioStateUnavailable(const AppExecFwk::InnerEvent::Pointer & event)947 bool SimStateHandle::IsRadioStateUnavailable(const AppExecFwk::InnerEvent::Pointer &event)
948 {
949 std::shared_ptr<Int32Parcel> object = event->GetSharedObject<Int32Parcel>();
950 if (object == nullptr) {
951 TELEPHONY_LOGE("object is nullptr!");
952 return false;
953 }
954 int32_t radioState = object->data;
955 if (radioState == ModemPowerState::CORE_SERVICE_POWER_NOT_AVAILABLE) {
956 TELEPHONY_LOGI("received radio unavailable");
957 IccState iccState;
958 iccState.simType_ = ICC_UNKNOWN_TYPE;
959 iccState.simStatus_ = ICC_CONTENT_UNKNOWN;
960 modemInitDone_ = false;
961 ProcessIccCardState(iccState, slotId_);
962 return true;
963 }
964 return false;
965 }
966
GetSimIO(int32_t slotId,SimIoRequestInfo requestInfo)967 int32_t SimStateHandle::GetSimIO(int32_t slotId, SimIoRequestInfo requestInfo)
968 {
969 auto event = AppExecFwk::InnerEvent::Get(MSG_SIM_GET_SIM_IO_DONE);
970 if (event == nullptr) {
971 TELEPHONY_LOGE("event is nullptr!");
972 return SIM_AUTH_FAIL;
973 }
974 event->SetOwner(shared_from_this());
975 auto telRilManager = telRilManager_.lock();
976 if (telRilManager == nullptr) {
977 TELEPHONY_LOGE("SimStateHandle::GetSimIO() telRilManager is nullptr!!");
978 return SIM_AUTH_FAIL;
979 }
980 return telRilManager->GetSimIO(slotId, requestInfo, event);
981 }
982
GetSimIOResult(int32_t slotId,const AppExecFwk::InnerEvent::Pointer & event)983 void SimStateHandle::GetSimIOResult(int32_t slotId, const AppExecFwk::InnerEvent::Pointer &event)
984 {
985 TELEPHONY_LOGI("SimStateHandle::GetSimIOResult slotId = %{public}d", slotId);
986 auto response = event->GetSharedObject<IccIoResultInfo>();
987 if (response == nullptr) {
988 TELEPHONY_LOGE("SimStateHandle::GetSimIOResult() fail");
989 return;
990 }
991 simIORespon_.sw1 = response->sw1;
992 simIORespon_.sw2 = response->sw2;
993 simIORespon_.response = response->response;
994 }
995
GetSimIOResponse()996 SimAuthenticationResponse SimStateHandle::GetSimIOResponse()
997 {
998 return simIORespon_;
999 }
1000 } // namespace Telephony
1001 } // namespace OHOS
1002