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 "network_search_handler.h"
17
18 #include "core_service_errors.h"
19 #include "core_manager_inner.h"
20 #include "ims_core_service_client.h"
21 #include "mcc_pool.h"
22 #include "network_search_manager.h"
23 #include "resource_utils.h"
24 #include "satellite_service_client.h"
25 #include "telephony_ext_wrapper.h"
26 #include "telephony_log_wrapper.h"
27
28 namespace OHOS {
29 namespace Telephony {
30 std::mutex NetworkSearchManager::ctx_;
31 bool NetworkSearchManager::ssbResponseReady_ = false;
32 std::condition_variable NetworkSearchManager::cv_;
33 static const int32_t REQ_INTERVAL = 30;
34 const int32_t SATELLITE_STATUS_ON = 1;
35 const size_t MCC_LEN = 3;
36 const std::string PERMISSION_PUBLISH_SYSTEM_EVENT = "ohos.permission.PUBLISH_SYSTEM_COMMON_EVENT";
37 const std::map<uint32_t, NetworkSearchHandler::NsHandlerFunc> NetworkSearchHandler::memberFuncMap_ = {
38 { RadioEvent::RADIO_SIM_STATE_CHANGE,
__anonae1e7eff0102() 39 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
40 handler->SimStateChange(event);
41 } },
42 { RadioEvent::RADIO_IMSI_LOADED_READY,
__anonae1e7eff0202() 43 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
44 handler->ImsiLoadedReady(event);
45 } },
46 { RadioEvent::RADIO_SIM_RECORDS_LOADED,
__anonae1e7eff0302() 47 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
48 handler->SimRecordsLoaded(event);
49 } },
50 { RadioEvent::RADIO_STATE_CHANGED,
__anonae1e7eff0402() 51 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
52 handler->RadioStateChange(event);
53 } },
54 { RadioEvent::RADIO_NETWORK_STATE,
__anonae1e7eff0502() 55 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
56 handler->GetNetworkStateInfo(event);
57 } },
58 { RadioEvent::RADIO_RESTRICTED_STATE,
__anonae1e7eff0602() 59 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
60 handler->RadioRestrictedState(event);
61 } },
62 { RadioEvent::RADIO_DATA_REG_STATE,
__anonae1e7eff0702() 63 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
64 handler->RadioRilDataRegState(event);
65 } },
66 { RadioEvent::RADIO_VOICE_REG_STATE,
__anonae1e7eff0802() 67 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
68 handler->RadioRilVoiceRegState(event);
69 } },
70 { RadioEvent::RADIO_GET_SIGNAL_STRENGTH,
__anonae1e7eff0902() 71 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
72 handler->RadioSignalStrength(event);
73 } },
74 { RadioEvent::RADIO_SIGNAL_STRENGTH_UPDATE,
__anonae1e7eff0a02() 75 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
76 handler->RadioSignalStrength(event);
77 } },
78 { RadioEvent::RADIO_OPERATOR,
__anonae1e7eff0b02() 79 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
80 handler->RadioRilOperator(event);
81 } },
82 { RadioEvent::RADIO_NETWORK_SEARCH_RESULT,
__anonae1e7eff0c02() 83 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
84 handler->NetworkSearchResult(event);
85 } },
86 { RadioEvent::RADIO_GET_NETWORK_SELECTION_MODE,
__anonae1e7eff0d02() 87 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
88 handler->GetNetworkSelectionModeResponse(event);
89 } },
90 { RadioEvent::RADIO_SET_NETWORK_SELECTION_MODE,
__anonae1e7eff0e02() 91 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
92 handler->SetNetworkSelectionModeResponse(event);
93 } },
94 { RadioEvent::RADIO_GET_STATUS,
__anonae1e7eff0f02() 95 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
96 handler->GetRadioStateResponse(event);
97 } },
98 { RadioEvent::RADIO_SET_STATUS,
__anonae1e7eff1002() 99 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
100 handler->SetRadioStateResponse(event);
101 } },
102 { RadioEvent::RADIO_SET_PREFERRED_NETWORK_MODE,
__anonae1e7eff1102() 103 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
104 handler->SetPreferredNetworkResponse(event);
105 } },
106 { RadioEvent::RADIO_GET_PREFERRED_NETWORK_MODE,
__anonae1e7eff1202() 107 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
108 handler->GetPreferredNetworkResponse(event);
109 } },
110 { RadioEvent::RADIO_NETWORK_TIME_UPDATE,
__anonae1e7eff1302() 111 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
112 handler->RadioNitzUpdate(event);
113 } },
114 { RadioEvent::RADIO_IMS_SERVICE_STATUS_UPDATE,
__anonae1e7eff1402() 115 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
116 handler->UpdateImsServiceStatus(event);
117 } },
118 { RadioEvent::RADIO_IMS_REGISTER_STATE_UPDATE,
__anonae1e7eff1502() 119 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
120 handler->UpdateImsRegisterState(event);
121 } },
122 { RadioEvent::RADIO_GET_IMEI,
__anonae1e7eff1602() 123 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
124 handler->RadioGetImei(event);
125 } },
126 { RadioEvent::RADIO_GET_IMEISV,
__anonae1e7eff1702() 127 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
128 handler->RadioGetImeiSv(event);
129 } },
130 { RadioEvent::RADIO_GET_MEID,
__anonae1e7eff1802() 131 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
132 handler->RadioGetMeid(event);
133 } },
134 { RadioEvent::RADIO_GET_NEIGHBORING_CELL_INFO,
__anonae1e7eff1902() 135 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
136 handler->RadioGetNeighboringCellInfo(event);
137 } },
138 { RadioEvent::RADIO_GET_CURRENT_CELL_INFO,
__anonae1e7eff1a02() 139 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
140 handler->RadioGetCurrentCellInfo(event);
141 } },
142 { RadioEvent::RADIO_CURRENT_CELL_UPDATE,
__anonae1e7eff1b02() 143 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
144 handler->RadioCurrentCellInfoUpdate(event);
145 } },
146 { RadioEvent::RADIO_CHANNEL_CONFIG_UPDATE,
__anonae1e7eff1c02() 147 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
148 handler->RadioChannelConfigInfo(event);
149 } },
150 { RadioEvent::RADIO_VOICE_TECH_CHANGED,
__anonae1e7eff1d02() 151 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
152 handler->RadioVoiceTechChange(event);
153 } },
154 { RadioEvent::RADIO_GET_VOICE_TECH,
__anonae1e7eff1e02() 155 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
156 handler->RadioVoiceTechChange(event);
157 } },
158 { RadioEvent::RADIO_SET_DATA_CONNECT_ACTIVE,
__anonae1e7eff1f02() 159 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
160 handler->DcPhysicalLinkActiveUpdate(event);
161 } },
162 { RadioEvent::RADIO_GET_BASEBAND_VERSION,
__anonae1e7eff2002() 163 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
164 handler->RadioGetBasebandVersion(event);
165 } },
166 { RadioEvent::RADIO_SET_NR_OPTION_MODE,
__anonae1e7eff2102() 167 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
168 handler->SetNrOptionModeResponse(event);
169 } },
170 { RadioEvent::RADIO_GET_NR_OPTION_MODE,
__anonae1e7eff2202() 171 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
172 handler->GetNrOptionModeResponse(event);
173 } },
174 { RadioEvent::RADIO_GET_RRC_CONNECTION_STATE,
__anonae1e7eff2302() 175 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
176 handler->RadioGetRrcConnectionState(event);
177 } },
178 { RadioEvent::RADIO_RRC_CONNECTION_STATE_UPDATE,
__anonae1e7eff2402() 179 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
180 handler->RadioGetRrcConnectionState(event);
181 } },
182 { RadioEvent::NOTIFY_STATE_CHANGE,
__anonae1e7eff2502() 183 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
184 handler->NotifyStateChange(event);
185 } },
186 { RadioEvent::DELAY_NOTIFY_STATE_CHANGE,
__anonae1e7eff2602() 187 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
188 handler->HandleDelayNotifyEvent(event);
189 } },
190 { RadioEvent::RADIO_RESIDENT_NETWORK_CHANGE,
__anonae1e7eff2702() 191 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
192 handler->RadioResidentNetworkChange(event);
193 } },
194 { RadioEvent::RADIO_GET_NR_SSBID_INFO,
__anonae1e7eff2802() 195 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
196 handler->GetNrSsbIdResponse(event);
197 } },
198 { SettingEventCode::MSG_AUTO_TIME,
__anonae1e7eff2902() 199 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
200 handler->AutoTimeChange(event);
201 } },
202 { SettingEventCode::MSG_AUTO_TIMEZONE,
__anonae1e7eff2a02() 203 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
204 handler->AutoTimeZoneChange(event);
205 } },
206 { SettingEventCode::MSG_AUTO_AIRPLANE_MODE,
__anonae1e7eff2b02() 207 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
208 handler->AirplaneModeChange(event);
209 } },
210 { RadioEvent::SATELLITE_STATUS_CHANGED,
__anonae1e7eff2c02() 211 [](NetworkSearchHandler *handler, const AppExecFwk::InnerEvent::Pointer &event) {
212 handler->SatelliteStatusChanged(event);
213 } }
214 };
215
NetworkSearchHandler(const std::weak_ptr<NetworkSearchManager> & networkSearchManager,const std::weak_ptr<ITelRilManager> & telRilManager,const std::weak_ptr<ISimManager> & simManager,int32_t slotId)216 NetworkSearchHandler::NetworkSearchHandler(const std::weak_ptr<NetworkSearchManager> &networkSearchManager,
217 const std::weak_ptr<ITelRilManager> &telRilManager, const std::weak_ptr<ISimManager> &simManager, int32_t slotId)
218 : TelEventHandler("NetworkSearchManager_" + std::to_string(slotId)), networkSearchManager_(networkSearchManager),
219 telRilManager_(telRilManager), simManager_(simManager), slotId_(slotId)
220 {}
221
~NetworkSearchHandler()222 NetworkSearchHandler::~NetworkSearchHandler()
223 {
224 if (statusChangeListener_ != nullptr) {
225 statusChangeListener_.clear();
226 statusChangeListener_ = nullptr;
227 }
228 }
229
Init()230 bool NetworkSearchHandler::Init()
231 {
232 ResourceUtils::Get().GetBooleanValueByName(ResourceUtils::IS_CS_CAPABLE, isCsCapable_);
233 std::shared_ptr<NetworkSearchManager> nsm = networkSearchManager_.lock();
234 if (nsm == nullptr) {
235 TELEPHONY_LOGE("failed to get NetworkSearchManager");
236 return false;
237 }
238 networkRegister_ = std::make_unique<NetworkRegister>(nsm->GetNetworkSearchState(slotId_), nsm, slotId_);
239 if (networkRegister_ == nullptr) {
240 TELEPHONY_LOGE("failed to create new networkRegister slotId:%{public}d", slotId_);
241 return false;
242 }
243 networkRegister_->InitNrConversionConfig();
244 if (!InitOperatorName() || !InitSettingUtils()) {
245 return false;
246 }
247 SubscribeSystemAbility();
248 radioInfo_ = std::make_unique<RadioInfo>(nsm, slotId_);
249 if (radioInfo_ == nullptr) {
250 TELEPHONY_LOGE("failed to create new radioInfo slotId:%{public}d", slotId_);
251 return false;
252 }
253 signalInfo_ = std::make_unique<SignalInfo>();
254 if (signalInfo_ == nullptr) {
255 TELEPHONY_LOGE("failed to create new signalInfo slotId:%{public}d", slotId_);
256 return false;
257 }
258 networkSelection_ = std::make_unique<NetworkSelection>(networkSearchManager_, slotId_);
259 if (networkSelection_ == nullptr) {
260 TELEPHONY_LOGE("failed to create new networkSelection slotId:%{public}d", slotId_);
261 return false;
262 }
263 networkType_ = std::make_unique<NetworkType>(nsm, slotId_);
264 if (networkType_ == nullptr) {
265 TELEPHONY_LOGE("failed to create new networkType slotId:%{public}d", slotId_);
266 return false;
267 }
268 nitzUpdate_ = std::make_unique<NitzUpdate>(networkSearchManager_, slotId_);
269 if (nitzUpdate_ == nullptr) {
270 TELEPHONY_LOGE("failed to create new nitzUpdate slotId:%{public}d", slotId_);
271 return false;
272 }
273 if (!SubModuleInit()) {
274 return false;
275 }
276 signalInfo_->InitSignalBar();
277 RegisterEvents();
278 return true;
279 }
280
SubModuleInit()281 bool NetworkSearchHandler::SubModuleInit()
282 {
283 cellInfo_ = std::make_unique<CellInfo>(networkSearchManager_, slotId_);
284 if (cellInfo_ == nullptr) {
285 TELEPHONY_LOGE("failed to create new CellInfo slotId:%{public}d", slotId_);
286 return false;
287 }
288 nrSsbInfo_ = std::make_unique<NrSsbInfo>(networkSearchManager_, slotId_);
289 if (nrSsbInfo_ == nullptr) {
290 TELEPHONY_LOGE("failed to create new NrSsbInfo slotId:%{public}d", slotId_);
291 return false;
292 }
293 return true;
294 }
295
InitOperatorName()296 bool NetworkSearchHandler::InitOperatorName()
297 {
298 std::shared_ptr<NetworkSearchManager> nsm = networkSearchManager_.lock();
299 EventFwk::MatchingSkills matchingSkills;
300 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED);
301 matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_LOCALE_CHANGED);
302 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
303 subscriberInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
304 operatorName_ = std::make_shared<OperatorName>(
305 subscriberInfo, nsm->GetNetworkSearchState(slotId_), nsm->GetSimManager(), networkSearchManager_, slotId_);
306 if (operatorName_ == nullptr) {
307 TELEPHONY_LOGE("failed to create new operatorName slotId:%{public}d", slotId_);
308 return false;
309 }
310 return true;
311 }
312
InitSettingUtils()313 bool NetworkSearchHandler::InitSettingUtils()
314 {
315 EventFwk::MatchingSkills matchingSkills;
316 matchingSkills.AddEvent(SettingUtils::COMMON_EVENT_DATA_SHARE_READY);
317 EventFwk::CommonEventSubscribeInfo subscriberInfo(matchingSkills);
318 subscriberInfo.SetThreadMode(EventFwk::CommonEventSubscribeInfo::COMMON);
319 subscriberInfo.SetPermission(PERMISSION_PUBLISH_SYSTEM_EVENT);
320 SettingUtils::GetInstance()->SetCommonEventSubscribeInfo(subscriberInfo);
321 if (SettingUtils::GetInstance()->GetCommonEventSubscriber() == nullptr) {
322 TELEPHONY_LOGE("InitSettingUtils fail! slotId:%{public}d", slotId_);
323 return false;
324 }
325 return true;
326 }
327
SubscribeSystemAbility()328 void NetworkSearchHandler::SubscribeSystemAbility()
329 {
330 auto samgrProxy = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
331 statusChangeListener_ = new (std::nothrow) SystemAbilityStatusChangeListener(operatorName_);
332 if (samgrProxy == nullptr || statusChangeListener_ == nullptr) {
333 TELEPHONY_LOGE("SubscribeSystemAbility samgrProxy or statusChangeListener_ is nullptr");
334 } else {
335 int32_t commonEventResult = samgrProxy->SubscribeSystemAbility(COMMON_EVENT_SERVICE_ID, statusChangeListener_);
336 int32_t DataShareResult = samgrProxy->SubscribeSystemAbility(DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID,
337 statusChangeListener_);
338 TELEPHONY_LOGI("SubscribeSystemAbility COMMON_EVENT_SERVICE_ID result:%{public}d"
339 "DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID result:%{public}d.", commonEventResult, DataShareResult);
340 }
341 }
342
RegisterEvents()343 void NetworkSearchHandler::RegisterEvents()
344 {
345 TELEPHONY_LOGD("NetworkSearchHandler::RegisterEvents start slotId:%{public}d", slotId_);
346 // Register SIM
347 {
348 std::shared_ptr<ISimManager> simManager = simManager_.lock();
349 if (simManager != nullptr) {
350 simManager->RegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_SIM_STATE_CHANGE);
351 simManager->RegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_IMSI_LOADED_READY);
352 simManager->RegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_SIM_RECORDS_LOADED);
353 }
354 }
355 // unsol RIL
356 {
357 std::shared_ptr<ITelRilManager> telRilManager = telRilManager_.lock();
358 if (telRilManager != nullptr) {
359 telRilManager->RegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_STATE_CHANGED, nullptr);
360 telRilManager->RegisterCoreNotify(
361 slotId_, shared_from_this(), RadioEvent::RADIO_SIGNAL_STRENGTH_UPDATE, nullptr);
362 telRilManager->RegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_NETWORK_STATE, nullptr);
363 telRilManager->RegisterCoreNotify(
364 slotId_, shared_from_this(), RadioEvent::RADIO_NETWORK_TIME_UPDATE, nullptr);
365 telRilManager->RegisterCoreNotify(
366 slotId_, shared_from_this(), RadioEvent::RADIO_CHANNEL_CONFIG_UPDATE, nullptr);
367 telRilManager->RegisterCoreNotify(
368 slotId_, shared_from_this(), RadioEvent::RADIO_VOICE_TECH_CHANGED, nullptr);
369 telRilManager->RegisterCoreNotify(
370 slotId_, shared_from_this(), RadioEvent::RADIO_CURRENT_CELL_UPDATE, nullptr);
371 telRilManager->RegisterCoreNotify(
372 slotId_, shared_from_this(), RadioEvent::RADIO_RRC_CONNECTION_STATE_UPDATE, nullptr);
373 telRilManager->RegisterCoreNotify(
374 slotId_, shared_from_this(), RadioEvent::RADIO_RESIDENT_NETWORK_CHANGE, nullptr);
375 }
376 }
377 {
378 if (IsSatelliteSupported() == static_cast<int32_t>(SatelliteValue::SATELLITE_SUPPORTED)) {
379 std::shared_ptr<SatelliteServiceClient> satelliteClient =
380 DelayedSingleton<SatelliteServiceClient>::GetInstance();
381 satelliteClient->AddNetworkHandler(slotId_, std::static_pointer_cast<TelEventHandler>(shared_from_this()));
382 }
383 }
384 // Register IMS
385 {
386 std::shared_ptr<ImsCoreServiceClient> imsCoreServiceClient =
387 DelayedSingleton<ImsCoreServiceClient>::GetInstance();
388 if (imsCoreServiceClient != nullptr) {
389 imsCoreServiceClient->RegisterImsCoreServiceCallbackHandler(slotId_, shared_from_this());
390 }
391 }
392 }
393
RegisterSatelliteCallback()394 void NetworkSearchHandler::RegisterSatelliteCallback()
395 {
396 if (IsSatelliteSupported() == static_cast<int32_t>(SatelliteValue::SATELLITE_SUPPORTED)) {
397 satelliteCallback_ =
398 std::make_unique<SatelliteCoreCallback>(std::static_pointer_cast<TelEventHandler>(shared_from_this()))
399 .release();
400 std::shared_ptr<SatelliteServiceClient> satelliteClient =
401 DelayedSingleton<SatelliteServiceClient>::GetInstance();
402 satelliteClient->RegisterCoreNotify(slotId_, RadioEvent::RADIO_SET_STATUS, satelliteCallback_);
403 satelliteClient->RegisterCoreNotify(slotId_, RadioEvent::RADIO_STATE_CHANGED, satelliteCallback_);
404 satelliteClient->RegisterCoreNotify(slotId_, RadioEvent::SATELLITE_STATUS_CHANGED, satelliteCallback_);
405 }
406 }
407
UnregisterSatelliteCallback()408 void NetworkSearchHandler::UnregisterSatelliteCallback()
409 {
410 if (IsSatelliteSupported() == static_cast<int32_t>(SatelliteValue::SATELLITE_SUPPORTED)) {
411 satelliteCallback_ = nullptr;
412 }
413 }
414
UnregisterEvents()415 void NetworkSearchHandler::UnregisterEvents()
416 {
417 {
418 std::shared_ptr<ISimManager> simManager = simManager_.lock();
419 if (simManager != nullptr) {
420 simManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_SIM_STATE_CHANGE);
421 simManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_IMSI_LOADED_READY);
422 simManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_SIM_RECORDS_LOADED);
423 }
424 }
425 // unsol
426 {
427 std::shared_ptr<ITelRilManager> telRilManager = telRilManager_.lock();
428 if (telRilManager != nullptr) {
429 telRilManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_STATE_CHANGED);
430 telRilManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_SIGNAL_STRENGTH_UPDATE);
431 telRilManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_NETWORK_STATE);
432 telRilManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_NETWORK_TIME_UPDATE);
433 telRilManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_CHANNEL_CONFIG_UPDATE);
434 telRilManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_VOICE_TECH_CHANGED);
435 telRilManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_CURRENT_CELL_UPDATE);
436 telRilManager->UnRegisterCoreNotify(
437 slotId_, shared_from_this(), RadioEvent::RADIO_RRC_CONNECTION_STATE_UPDATE);
438 telRilManager->UnRegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_RESIDENT_NETWORK_CHANGE);
439 }
440 }
441 if (IsSatelliteSupported() == static_cast<int32_t>(SatelliteValue::SATELLITE_SUPPORTED) &&
442 satelliteCallback_ != nullptr) {
443 std::shared_ptr<SatelliteServiceClient> satelliteClient =
444 DelayedSingleton<SatelliteServiceClient>::GetInstance();
445 satelliteClient->UnRegisterCoreNotify(slotId_, RadioEvent::RADIO_STATE_CHANGED);
446 satelliteClient->UnRegisterCoreNotify(slotId_, RadioEvent::RADIO_SET_STATUS);
447 satelliteClient->UnRegisterCoreNotify(slotId_, RadioEvent::SATELLITE_STATUS_CHANGED);
448 }
449 }
450
ProcessEvent(const AppExecFwk::InnerEvent::Pointer & event)451 void NetworkSearchHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
452 {
453 if (event == nullptr) {
454 return;
455 }
456 auto msgType = event->GetInnerEventId();
457 TELEPHONY_LOGD(
458 "NetworkSearchHandler::ProcessEvent received event slotId:%{public}d msgType:%{public}d", slotId_, msgType);
459 auto itFunc = memberFuncMap_.find(static_cast<RadioEvent>(msgType));
460 if (itFunc != memberFuncMap_.end()) {
461 auto memberFunc = itFunc->second;
462 if (memberFunc != nullptr) {
463 memberFunc(this, event);
464 }
465 }
466 }
467
SimStateChange(const AppExecFwk::InnerEvent::Pointer &)468 void NetworkSearchHandler::SimStateChange(const AppExecFwk::InnerEvent::Pointer &)
469 {
470 std::shared_ptr<ISimManager> simManager = simManager_.lock();
471 if (simManager != nullptr) {
472 simManager->RegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_IMSI_LOADED_READY);
473 simManager->RegisterCoreNotify(slotId_, shared_from_this(), RadioEvent::RADIO_SIM_RECORDS_LOADED);
474 }
475 }
476
ImsiLoadedReady(const AppExecFwk::InnerEvent::Pointer & event)477 void NetworkSearchHandler::ImsiLoadedReady(const AppExecFwk::InnerEvent::Pointer &event)
478 {
479 SendUpdateCellLocationRequest();
480 InitGetNetworkSelectionMode();
481 GetNetworkStateInfo(event);
482 }
483
SimRecordsLoaded(const AppExecFwk::InnerEvent::Pointer &)484 void NetworkSearchHandler::SimRecordsLoaded(const AppExecFwk::InnerEvent::Pointer &)
485 {
486 auto networkSearchManager = networkSearchManager_.lock();
487 if (networkSearchManager != nullptr) {
488 int32_t csRadioTech = 0;
489 int32_t psRadioTech = 0;
490 networkSearchManager->GetCsRadioTech(slotId_, csRadioTech);
491 networkSearchManager->GetPsRadioTech(slotId_, psRadioTech);
492 UpdatePhone(static_cast<RadioTech>(csRadioTech), static_cast<RadioTech>(psRadioTech));
493 }
494
495 if (operatorName_ != nullptr) {
496 operatorName_->NotifySpnChanged();
497 }
498 }
499
RadioStateChange(const AppExecFwk::InnerEvent::Pointer & event)500 void NetworkSearchHandler::RadioStateChange(const AppExecFwk::InnerEvent::Pointer &event)
501 {
502 if (event == nullptr) {
503 TELEPHONY_LOGE("NetworkSearchHandler::RadioStateChange event is nullptr!");
504 return;
505 }
506 std::shared_ptr<Int32Parcel> object = event->GetSharedObject<Int32Parcel>();
507 if (object == nullptr) {
508 TELEPHONY_LOGE("NetworkSearchHandler::RadioStateChange object is nullptr!");
509 return;
510 }
511 auto networkSearchManager = networkSearchManager_.lock();
512 if (networkSearchManager == nullptr) {
513 TELEPHONY_LOGE("NetworkSearchHandler::RadioStateChange failed to get NetworkSearchManager");
514 return;
515 }
516 int32_t radioState = object->data;
517 TELEPHONY_LOGI("NetworkSearchHandler::RadioState change: %{public}d, slotId: %{public}d", radioState, slotId_);
518 switch (radioState) {
519 case CORE_SERVICE_POWER_NOT_AVAILABLE:
520 case CORE_SERVICE_POWER_OFF: {
521 RadioOffOrUnavailableState(radioState);
522 break;
523 }
524 case CORE_SERVICE_POWER_ON: {
525 firstInit_ = false;
526 InitGetNetworkSelectionMode();
527 SetRadioOffWhenAirplaneIsOn();
528 RadioOnState();
529 break;
530 }
531 default:
532 TELEPHONY_LOGI("Unhandled message with number: %{public}d", radioState);
533 break;
534 }
535 if (radioState == CORE_SERVICE_POWER_ON || radioState == CORE_SERVICE_POWER_OFF) {
536 networkSearchManager->SetRadioStateValue(slotId_, (ModemPowerState)radioState);
537 auto inner = networkSearchManager->FindManagerInner(slotId_);
538 if (inner != nullptr && inner->deviceStateHandler_ != nullptr) {
539 inner->deviceStateHandler_->ProcessRadioState();
540 }
541 networkSearchManager->InitSimRadioProtocol(slotId_);
542 std::u16string imei = u"";
543 networkSearchManager->GetImei(slotId_, imei);
544 } else {
545 networkSearchManager->SetRadioStateValue(slotId_, CORE_SERVICE_POWER_NOT_AVAILABLE);
546 }
547 if (operatorName_ != nullptr) {
548 operatorName_->NotifySpnChanged();
549 }
550 }
551
SetRadioOffWhenAirplaneIsOn()552 void NetworkSearchHandler::SetRadioOffWhenAirplaneIsOn()
553 {
554 bool isAirplaneMode = false;
555 auto networkSearchManager = networkSearchManager_.lock();
556 if (networkSearchManager == nullptr) {
557 TELEPHONY_LOGE("NetworkSearchHandler::SetRadioOffWhenAirplaneIsOn failed to get NetworkSearchManager");
558 return;
559 }
560 if (networkSearchManager->GetAirplaneMode(isAirplaneMode) == TELEPHONY_SUCCESS && isAirplaneMode) {
561 networkSearchManager->SetRadioState(slotId_, static_cast<bool>(ModemPowerState::CORE_SERVICE_POWER_OFF), 0);
562 }
563 }
564
RadioRestrictedState(const AppExecFwk::InnerEvent::Pointer & event)565 void NetworkSearchHandler::RadioRestrictedState(const AppExecFwk::InnerEvent::Pointer &event)
566 {
567 if (event == nullptr) {
568 TELEPHONY_LOGE("NetworkSearchHandler::RadioRestrictedState event is nullptr!");
569 return;
570 }
571 if (networkRegister_ != nullptr) {
572 networkRegister_->ProcessRestrictedState(event);
573 }
574 TELEPHONY_LOGD("NetworkSearchHandler::RadioRestrictedState slotId:%{public}d", slotId_);
575 }
576
RadioRilDataRegState(const AppExecFwk::InnerEvent::Pointer & event)577 void NetworkSearchHandler::RadioRilDataRegState(const AppExecFwk::InnerEvent::Pointer &event)
578 {
579 if (event == nullptr) {
580 TELEPHONY_LOGE("NetworkSearchHandler::RadioRilDataRegState event is nullptr!");
581 return;
582 }
583 auto networkSearchManager = networkSearchManager_.lock();
584 if (networkSearchManager == nullptr ||
585 networkSearchManager->GetRadioState(slotId_) == static_cast<int>(ModemPowerState::CORE_SERVICE_POWER_OFF)) {
586 TELEPHONY_LOGI("radio is power off, no need update data reg state");
587 return;
588 }
589 std::lock_guard<std::mutex> lock(mutex_);
590 psRegStatusResultInfo_ = event->GetSharedObject<PsRegStatusResultInfo>();
591 if (psRegStatusResultInfo_ == nullptr) {
592 TELEPHONY_LOGE("psRegStatusResult is nullptr slotId:%{public}d", slotId_);
593 return;
594 }
595 if (psRegStatusResultInfo_->flag != networkSearchManager->GetSerialNum(slotId_)) {
596 TELEPHONY_LOGI("Aborting outdated ps registration event slotId:%{public}d", slotId_);
597 return;
598 }
599 networkSearchManager->decMsgNum(slotId_);
600 TelRilRegStatus regStatus = psRegStatusResultInfo_->regStatus;
601 bool isEmergency = (regStatus == TelRilRegStatus::REG_MT_EMERGENCY) && isCsCapable_;
602 if (networkSearchManager->CheckIsNeedNotify(slotId_) || isEmergency) {
603 UpdateNetworkState();
604 }
605 TELEPHONY_LOGD("NetworkSearchHandler::RadioRilDataRegState slotId:%{public}d", slotId_);
606 }
607
RadioRilVoiceRegState(const AppExecFwk::InnerEvent::Pointer & event)608 void NetworkSearchHandler::RadioRilVoiceRegState(const AppExecFwk::InnerEvent::Pointer &event)
609 {
610 if (event == nullptr) {
611 TELEPHONY_LOGE("NetworkSearchHandler::RadioRilVoiceRegState event is nullptr!");
612 return;
613 }
614 auto networkSearchManager = networkSearchManager_.lock();
615 if (networkSearchManager == nullptr ||
616 networkSearchManager->GetRadioState(slotId_) == static_cast<int>(ModemPowerState::CORE_SERVICE_POWER_OFF)) {
617 TELEPHONY_LOGI("radio is power off, no need update voice reg state");
618 return;
619 }
620 std::lock_guard<std::mutex> lock(mutex_);
621 csRegStatusInfo_ = event->GetSharedObject<CsRegStatusInfo>();
622 if (csRegStatusInfo_ == nullptr) {
623 TELEPHONY_LOGE("csRegStatusResult is nullptr slotId:%{public}d", slotId_);
624 return;
625 }
626 if (csRegStatusInfo_->flag != networkSearchManager->GetSerialNum(slotId_)) {
627 TELEPHONY_LOGI("Aborting outdated cs registration event slotId:%{public}d", slotId_);
628 return;
629 }
630 networkSearchManager->decMsgNum(slotId_);
631 TelRilRegStatus regStatus = csRegStatusInfo_->regStatus;
632 bool isEmergency = (regStatus == TelRilRegStatus::REG_MT_EMERGENCY) && isCsCapable_;
633 if (networkSearchManager->CheckIsNeedNotify(slotId_) || isEmergency) {
634 UpdateNetworkState();
635 }
636 TELEPHONY_LOGD("NetworkSearchHandler::RadioRilVoiceRegState slotId:%{public}d", slotId_);
637 }
638
RadioSignalStrength(const AppExecFwk::InnerEvent::Pointer & event)639 void NetworkSearchHandler::RadioSignalStrength(const AppExecFwk::InnerEvent::Pointer &event)
640 {
641 if (event == nullptr) {
642 TELEPHONY_LOGE("NetworkSearchHandler::RadioSignalStrength event is nullptr!");
643 return;
644 }
645 if (signalInfo_ != nullptr) {
646 signalInfo_->ProcessSignalIntensity(slotId_, event);
647 }
648 TELEPHONY_LOGD("NetworkSearchHandler::RadioSignalStrength slotId:%{public}d", slotId_);
649 }
650
RadioRilOperator(const AppExecFwk::InnerEvent::Pointer & event)651 void NetworkSearchHandler::RadioRilOperator(const AppExecFwk::InnerEvent::Pointer &event)
652 {
653 if (event == nullptr) {
654 TELEPHONY_LOGE("NetworkSearchHandler::RadioRilOperator event is nullptr!");
655 return;
656 }
657 auto networkSearchManager = networkSearchManager_.lock();
658 if (networkSearchManager == nullptr ||
659 networkSearchManager->GetRadioState(slotId_) == static_cast<int>(ModemPowerState::CORE_SERVICE_POWER_OFF)) {
660 TELEPHONY_LOGI("radio is power off, no need update operator info");
661 return;
662 }
663 std::lock_guard<std::mutex> lock(mutex_);
664 operatorInfoResult_ = event->GetSharedObject<OperatorInfoResult>();
665 if (operatorInfoResult_ == nullptr) {
666 TELEPHONY_LOGE("operatorInfoResult is nullptr slotId:%{public}d", slotId_);
667 return;
668 }
669 if (operatorInfoResult_->flag == networkSearchManager->GetSerialNum(slotId_)) {
670 networkSearchManager->decMsgNum(slotId_);
671 if (networkSearchManager->CheckIsNeedNotify(slotId_)) {
672 UpdateNetworkState();
673 }
674 } else if (operatorInfoResult_->flag == NetworkSearchManagerInner::SERIAL_NUMBER_EXEMPT) {
675 if (operatorName_ != nullptr) {
676 operatorName_->HandleOperatorInfo(operatorInfoResult_);
677 }
678 } else {
679 TELEPHONY_LOGI("Aborting outdated operator info event slotId:%{public}d", slotId_);
680 }
681 TELEPHONY_LOGD("NetworkSearchHandler::RadioRilOperator slotId:%{public}d", slotId_);
682 }
683
UpdateNetworkState()684 void NetworkSearchHandler::UpdateNetworkState()
685 {
686 if (networkRegister_ != nullptr) {
687 networkRegister_->ProcessPsRegister(psRegStatusResultInfo_);
688 networkRegister_->ProcessCsRegister(csRegStatusInfo_);
689 }
690 if (operatorName_ != nullptr) {
691 operatorName_->HandleOperatorInfo(operatorInfoResult_);
692 operatorName_->TrySetLongOperatorNameWithTranslation();
693 }
694 auto networkSearchManager = networkSearchManager_.lock();
695 if (networkSearchManager != nullptr) {
696 networkSearchManager->ProcessNotifyStateChangeEvent(slotId_);
697 }
698 TELEPHONY_LOGI("NetworkSearchHandler::UpdateNetworkState slotId:%{public}d", slotId_);
699 }
700
GetRilSignalIntensity(bool checkTime)701 void NetworkSearchHandler::GetRilSignalIntensity(bool checkTime)
702 {
703 TELEPHONY_LOGD("NetworkSearchHandler::GetRilSignalIntensity start...... slotId:%{public}d", slotId_);
704 if (!TimeOutCheck(lastTimeSignalReq_, checkTime)) {
705 return;
706 }
707
708 auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_SIGNAL_STRENGTH);
709 if (event != nullptr) {
710 event->SetOwner(shared_from_this());
711 std::shared_ptr<ITelRilManager> telRilManager = telRilManager_.lock();
712 if (telRilManager != nullptr) {
713 telRilManager->GetSignalStrength(slotId_, event);
714 }
715 }
716 }
717
GetNetworkStateInfo(const AppExecFwk::InnerEvent::Pointer &)718 void NetworkSearchHandler::GetNetworkStateInfo(const AppExecFwk::InnerEvent::Pointer &)
719 {
720 auto networkSearchManager = networkSearchManager_.lock();
721 if (networkSearchManager == nullptr) {
722 TELEPHONY_LOGE("failed to get NetworkSearchManager RadioState slotId:%{public}d", slotId_);
723 return;
724 }
725 std::shared_ptr<NetworkSearchState> networkSearchState = networkSearchManager->GetNetworkSearchState(slotId_);
726 if (networkSearchState == nullptr) {
727 TELEPHONY_LOGE("networkSearchState is null slotId:%{public}d", slotId_);
728 return;
729 }
730
731 ModemPowerState radioState = static_cast<ModemPowerState>(networkSearchManager->GetRadioState(slotId_));
732 TELEPHONY_LOGI("NetworkSearchHandler GetRadioState : %{public}d slotId:%{public}d", radioState, slotId_);
733 switch (radioState) {
734 case CORE_SERVICE_POWER_NOT_AVAILABLE:
735 case CORE_SERVICE_POWER_OFF:
736 RadioOffOrUnavailableState(radioState);
737 break;
738 case CORE_SERVICE_POWER_ON: {
739 firstInit_ = false;
740 RadioOnState();
741 break;
742 }
743 default:
744 TELEPHONY_LOGI("Unhandled message with number: %{public}d slotId:%{public}d", radioState, slotId_);
745 break;
746 }
747 }
748
RadioOnWhenHasSim(std::shared_ptr<NetworkSearchManager> & networkSearchManager,int32_t radioState) const749 void NetworkSearchHandler::RadioOnWhenHasSim(std::shared_ptr<NetworkSearchManager> &networkSearchManager,
750 int32_t radioState) const
751 {
752 bool isAirplaneMode = false;
753 if (networkSearchManager->GetAirplaneMode(isAirplaneMode) != TELEPHONY_SUCCESS) {
754 TELEPHONY_LOGE("RadioOffOrUnavailableState GetAirplaneMode fail slotId: %{public}d", slotId_);
755 }
756 auto simManager = networkSearchManager->GetSimManager();
757 if (simManager == nullptr) {
758 return;
759 }
760 bool hasSim = false;
761 simManager->HasSimCard(slotId_, hasSim);
762 if (!isAirplaneMode && (hasSim || IsPowerOnPrimaryRadioWhenNoSim()) && radioState == CORE_SERVICE_POWER_OFF &&
763 !IsSatelliteOn()) {
764 networkSearchManager->SetRadioState(slotId_, static_cast<bool>(ModemPowerState::CORE_SERVICE_POWER_ON), 0);
765 }
766 }
767
RadioOffOrUnavailableState(int32_t radioState) const768 void NetworkSearchHandler::RadioOffOrUnavailableState(int32_t radioState) const
769 {
770 TELEPHONY_LOGD("RadioOffOrUnavailableState enter... slotId:%{public}d", slotId_);
771 auto networkSearchManager = networkSearchManager_.lock();
772 if (networkSearchManager == nullptr) {
773 TELEPHONY_LOGE("RadioOffOrUnavailableState NetworkSearchHandler is null slotId:%{public}d", slotId_);
774 return;
775 }
776 networkSearchManager->SetResidentNetworkNumeric(slotId_, "");
777 std::shared_ptr<NetworkSearchState> networkSearchState = networkSearchManager->GetNetworkSearchState(slotId_);
778 if (networkSearchState == nullptr) {
779 TELEPHONY_LOGE("networkSearchState is null slotId:%{public}d", slotId_);
780 return;
781 }
782 networkSearchState->SetInitial();
783 RegServiceState regState = radioState == CORE_SERVICE_POWER_OFF ?
784 RegServiceState::REG_STATE_POWER_OFF : RegServiceState::REG_STATE_NO_SERVICE;
785 networkSearchState->SetNetworkState(regState, DomainType::DOMAIN_TYPE_CS);
786 networkSearchState->SetNetworkState(regState, DomainType::DOMAIN_TYPE_PS);
787 ClearSignalAndCellInfoList();
788 networkSearchState->NotifyStateChange();
789 networkSearchManager->UpdateNrOptionMode(slotId_, NrMode::NR_MODE_UNKNOWN);
790
791 if (!TELEPHONY_EXT_WRAPPER.isHandleVSim_ || !TELEPHONY_EXT_WRAPPER.isHandleVSim_()) {
792 RadioOnWhenHasSim(networkSearchManager, radioState);
793 }
794
795 sptr<NetworkSearchCallBackBase> cellularData = networkSearchManager->GetCellularDataCallBack();
796 if (cellularData) {
797 cellularData->ClearCellularDataConnections(slotId_);
798 TELEPHONY_LOGD("RadioOffOrUnavailableState ClearCellularDataConnections");
799 }
800 sptr<NetworkSearchCallBackBase> cellularCall = networkSearchManager->GetCellularCallCallBack();
801 if (cellularCall) {
802 cellularCall->ClearCellularCallList(slotId_);
803 TELEPHONY_LOGD("RadioOffOrUnavailableState ClearCellularCallList");
804 }
805 }
806
RadioOnState()807 void NetworkSearchHandler::RadioOnState()
808 {
809 auto networkSearchManager = networkSearchManager_.lock();
810 int64_t serialNum = NetworkSearchManagerInner::SERIAL_NUMBER_DEFAULT;
811 if (networkSearchManager != nullptr) {
812 networkSearchManager->InitMsgNum(slotId_);
813 serialNum = networkSearchManager->IncreaseSerialNum(slotId_);
814 if (serialNum == NetworkSearchManagerInner::SERIAL_NUMBER_DEFAULT) {
815 TELEPHONY_LOGE("Invalid serial number slotId:%{public}d", slotId_);
816 return;
817 }
818 }
819 GetRilOperatorInfo(serialNum, false);
820 GetRilPsRegistration(serialNum, false);
821 GetRilCsRegistration(serialNum, false);
822 SendUpdateCellLocationRequest();
823 GetRilSignalIntensity(false);
824 }
825
GetRadioStateResponse(const AppExecFwk::InnerEvent::Pointer & event)826 void NetworkSearchHandler::GetRadioStateResponse(const AppExecFwk::InnerEvent::Pointer &event)
827 {
828 if (event == nullptr) {
829 TELEPHONY_LOGE("NetworkSearchHandler::GetRadioStateResponse event is nullptr!");
830 return;
831 }
832 if (radioInfo_ == nullptr) {
833 TELEPHONY_LOGE("RadioInfo is null slotId:%{public}d", slotId_);
834 return;
835 }
836 radioInfo_->ProcessGetRadioState(event);
837 }
838
SetRadioStateResponse(const AppExecFwk::InnerEvent::Pointer & event)839 void NetworkSearchHandler::SetRadioStateResponse(const AppExecFwk::InnerEvent::Pointer &event)
840 {
841 if (event == nullptr) {
842 TELEPHONY_LOGE("NetworkSearchHandler::SetRadioStateResponse event is nullptr!");
843 return;
844 }
845 if (radioInfo_ == nullptr) {
846 TELEPHONY_LOGE("RadioInfo is null slotId:%{public}d", slotId_);
847 return;
848 }
849 radioInfo_->ProcessSetRadioState(event);
850 }
851
GetRilOperatorInfo(int64_t serialNum,bool checkTime)852 void NetworkSearchHandler::GetRilOperatorInfo(int64_t serialNum, bool checkTime)
853 {
854 TELEPHONY_LOGD("NetworkSearchHandler::GetOperatorInfo start slotId:%{public}d", slotId_);
855 if (!TimeOutCheck(lastTimeOperatorReq_, checkTime)) {
856 return;
857 }
858
859 auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_OPERATOR, serialNum);
860 if (event != nullptr) {
861 event->SetOwner(shared_from_this());
862 std::shared_ptr<ITelRilManager> telRilManager = telRilManager_.lock();
863 if (telRilManager != nullptr) {
864 telRilManager->GetOperatorInfo(slotId_, event);
865 }
866 }
867 }
868
GetRilPsRegistration(int64_t serialNum,bool checkTime)869 void NetworkSearchHandler::GetRilPsRegistration(int64_t serialNum, bool checkTime)
870 {
871 TELEPHONY_LOGD("NetworkSearchHandler::GetPsRegStatus start slotId:%{public}d", slotId_);
872 if (!TimeOutCheck(lastTimePsRegistrationReq_, checkTime)) {
873 return;
874 }
875
876 auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_DATA_REG_STATE, serialNum);
877 if (event != nullptr) {
878 event->SetOwner(shared_from_this());
879 std::shared_ptr<ITelRilManager> telRilManager = telRilManager_.lock();
880 if (telRilManager != nullptr) {
881 telRilManager->GetPsRegStatus(slotId_, event);
882 }
883 }
884 }
885
InitGetNetworkSelectionMode()886 void NetworkSearchHandler::InitGetNetworkSelectionMode()
887 {
888 auto networkSearchManager = networkSearchManager_.lock();
889 if (networkSearchManager == nullptr) {
890 TELEPHONY_LOGE("InitGetNetworkSelectionMode networkSearchManager is null slotId:%{public}d", slotId_);
891 return;
892 }
893 networkSearchManager->GetNetworkSelectionMode(slotId_);
894 }
895
GetRilCsRegistration(int64_t serialNum,bool checkTime)896 void NetworkSearchHandler::GetRilCsRegistration(int64_t serialNum, bool checkTime)
897 {
898 TELEPHONY_LOGD("NetworkSearchHandler::GetCsRegStatus start slotId:%{public}d", slotId_);
899 if (!TimeOutCheck(lastTimeCsRegistrationReq_, checkTime)) {
900 return;
901 }
902
903 auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_VOICE_REG_STATE, serialNum);
904 if (event != nullptr) {
905 event->SetOwner(shared_from_this());
906 std::shared_ptr<ITelRilManager> telRilManager = telRilManager_.lock();
907 if (telRilManager != nullptr) {
908 telRilManager->GetCsRegStatus(slotId_, event);
909 }
910 }
911 }
912
NetworkSearchResult(const AppExecFwk::InnerEvent::Pointer & event)913 void NetworkSearchHandler::NetworkSearchResult(const AppExecFwk::InnerEvent::Pointer &event)
914 {
915 if (event == nullptr) {
916 TELEPHONY_LOGE("NetworkSearchHandler::NetworkSearchResult event is nullptr!");
917 return;
918 }
919 if (networkSelection_ == nullptr) {
920 TELEPHONY_LOGE("NetworkSearchResult NetworkSelection is null slotId:%{public}d", slotId_);
921 return;
922 }
923 networkSelection_->ProcessNetworkSearchResult(event);
924 }
925
SetNetworkSelectionModeResponse(const AppExecFwk::InnerEvent::Pointer & event)926 void NetworkSearchHandler::SetNetworkSelectionModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
927 {
928 if (event == nullptr) {
929 TELEPHONY_LOGE("NetworkSearchHandler::SetNetworkSelectionModeResponse event is nullptr!");
930 return;
931 }
932 if (networkSelection_ == nullptr) {
933 TELEPHONY_LOGE("SetNetworkSelectionModeResponse NetworkSelection is null slotId:%{public}d", slotId_);
934 return;
935 }
936 networkSelection_->ProcessSetNetworkSelectionMode(event);
937 }
938
GetNetworkSelectionModeResponse(const AppExecFwk::InnerEvent::Pointer & event)939 void NetworkSearchHandler::GetNetworkSelectionModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
940 {
941 if (event == nullptr) {
942 TELEPHONY_LOGE("NetworkSearchHandler::GetNetworkSelectionModeResponse event is nullptr!");
943 return;
944 }
945 if (networkSelection_ == nullptr) {
946 TELEPHONY_LOGE("GetNetworkSelectionModeResponse NetworkSelection is null slotId:%{public}d", slotId_);
947 return;
948 }
949 networkSelection_->ProcessGetNetworkSelectionMode(event);
950 }
951
GetSignalInfo(std::vector<sptr<SignalInformation>> & signals)952 void NetworkSearchHandler::GetSignalInfo(std::vector<sptr<SignalInformation>> &signals)
953 {
954 if (signalInfo_ != nullptr) {
955 signalInfo_->GetSignalInfoList(signals);
956 }
957 }
958
TimeOutCheck(int64_t & lastTime,bool checkTime)959 bool NetworkSearchHandler::TimeOutCheck(int64_t &lastTime, bool checkTime)
960 {
961 int64_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
962 if (!checkTime || (now - lastTime) > REQ_INTERVAL) {
963 lastTime = now;
964 return true;
965 }
966 return false;
967 }
968
GetPreferredNetworkResponse(const AppExecFwk::InnerEvent::Pointer & event)969 void NetworkSearchHandler::GetPreferredNetworkResponse(const AppExecFwk::InnerEvent::Pointer &event)
970 {
971 if (event == nullptr) {
972 TELEPHONY_LOGE("NetworkSearchHandler::GetPreferredNetworkResponse event is nullptr!");
973 return;
974 }
975 if (networkType_ != nullptr) {
976 networkType_->ProcessGetPreferredNetwork(event);
977 } else {
978 TELEPHONY_LOGE("GetPreferredNetworkResponse NetworkType is null slotId:%{public}d", slotId_);
979 }
980 }
981
SetPreferredNetworkResponse(const AppExecFwk::InnerEvent::Pointer & event)982 void NetworkSearchHandler::SetPreferredNetworkResponse(const AppExecFwk::InnerEvent::Pointer &event)
983 {
984 if (event == nullptr) {
985 TELEPHONY_LOGE("NetworkSearchHandler::SetPreferredNetworkResponse event is nullptr!");
986 return;
987 }
988 if (networkType_ != nullptr) {
989 networkType_->ProcessSetPreferredNetwork(event);
990 } else {
991 TELEPHONY_LOGE("SetPreferredNetworkResponse NetworkType is null slotId:%{public}d", slotId_);
992 }
993 }
994
RadioNitzUpdate(const AppExecFwk::InnerEvent::Pointer & event)995 void NetworkSearchHandler::RadioNitzUpdate(const AppExecFwk::InnerEvent::Pointer &event)
996 {
997 if (event == nullptr) {
998 TELEPHONY_LOGE("NetworkSearchHandler::RadioNitzUpdate event is nullptr!");
999 return;
1000 }
1001 if (nitzUpdate_ != nullptr) {
1002 nitzUpdate_->ProcessNitzUpdate(event);
1003 } else {
1004 TELEPHONY_LOGE("RadioNitzUpdate nitzUpdate is null slotId:%{public}d", slotId_);
1005 }
1006 }
1007
RadioGetImei(const AppExecFwk::InnerEvent::Pointer & event)1008 void NetworkSearchHandler::RadioGetImei(const AppExecFwk::InnerEvent::Pointer &event)
1009 {
1010 if (event == nullptr) {
1011 TELEPHONY_LOGE("NetworkSearchHandler::RadioGetImei event is nullptr!");
1012 return;
1013 }
1014 TELEPHONY_LOGD("NetworkSearchHandler::RadioGetImei start slotId:%{public}d", slotId_);
1015 if (radioInfo_ != nullptr) {
1016 radioInfo_->ProcessGetImei(event);
1017 } else {
1018 TELEPHONY_LOGE("RadioGetImei radioInfo_ is null slotId:%{public}d", slotId_);
1019 }
1020 }
1021
RadioGetImeiSv(const AppExecFwk::InnerEvent::Pointer & event)1022 void NetworkSearchHandler::RadioGetImeiSv(const AppExecFwk::InnerEvent::Pointer &event)
1023 {
1024 if (event == nullptr) {
1025 TELEPHONY_LOGE("NetworkSearchHandler::RadioGetImeiSv event is nullptr!");
1026 return;
1027 }
1028 TELEPHONY_LOGD("NetworkSearchHandler::RadioGetImeiSv start slotId:%{public}d", slotId_);
1029 if (radioInfo_ != nullptr) {
1030 radioInfo_->ProcessGetImeiSv(event);
1031 } else {
1032 TELEPHONY_LOGE("RadioGetImeiSv radioInfo_ is null slotId:%{public}d", slotId_);
1033 }
1034 }
1035
RadioGetMeid(const AppExecFwk::InnerEvent::Pointer & event)1036 void NetworkSearchHandler::RadioGetMeid(const AppExecFwk::InnerEvent::Pointer &event)
1037 {
1038 TELEPHONY_LOGD("NetworkSearchHandler::RadioGetMeid start slotId:%{public}d", slotId_);
1039 if (event == nullptr) {
1040 TELEPHONY_LOGE("NetworkSearchHandler::RadioGetMeid event is nullptr!");
1041 return;
1042 }
1043 if (radioInfo_ != nullptr) {
1044 radioInfo_->ProcessGetMeid(event);
1045 } else {
1046 TELEPHONY_LOGE("RadioGetMeid radioInfo_ is null slotId:%{public}d", slotId_);
1047 }
1048 }
1049
UpdatePhone(RadioTech csRadioTech,const RadioTech & psRadioTech) const1050 void NetworkSearchHandler::UpdatePhone(RadioTech csRadioTech, const RadioTech &psRadioTech) const
1051 {
1052 if (radioInfo_ != nullptr) {
1053 radioInfo_->UpdatePhone(csRadioTech, psRadioTech);
1054 } else {
1055 TELEPHONY_LOGE("UpdatePhone networkType is null slotId:%{public}d", slotId_);
1056 }
1057 }
1058
RadioGetCurrentCellInfo(const AppExecFwk::InnerEvent::Pointer & event)1059 void NetworkSearchHandler::RadioGetCurrentCellInfo(const AppExecFwk::InnerEvent::Pointer &event)
1060 {
1061 if (event == nullptr) {
1062 TELEPHONY_LOGE("NetworkSearchHandler::RadioGetCurrentCellInfo event is nullptr!");
1063 return;
1064 }
1065 if (cellInfo_ != nullptr) {
1066 cellInfo_->ProcessCurrentCellInfo(event);
1067 }
1068 }
1069
RadioCurrentCellInfoUpdate(const AppExecFwk::InnerEvent::Pointer & event)1070 void NetworkSearchHandler::RadioCurrentCellInfoUpdate(const AppExecFwk::InnerEvent::Pointer &event)
1071 {
1072 if (event == nullptr) {
1073 TELEPHONY_LOGE("NetworkSearchHandler::RadioCurrentCellInfoUpdate event is nullptr!");
1074 return;
1075 }
1076 if (cellInfo_ != nullptr) {
1077 cellInfo_->ProcessCurrentCellInfo(event);
1078 }
1079 }
1080
RadioGetNeighboringCellInfo(const AppExecFwk::InnerEvent::Pointer & event)1081 void NetworkSearchHandler::RadioGetNeighboringCellInfo(const AppExecFwk::InnerEvent::Pointer &event)
1082 {
1083 if (event == nullptr) {
1084 TELEPHONY_LOGE("NetworkSearchHandler::RadioGetNeighboringCellInfo event is nullptr!");
1085 return;
1086 }
1087 if (cellInfo_ != nullptr) {
1088 cellInfo_->ProcessNeighboringCellInfo(event);
1089 }
1090 }
1091
GetCellInfoList(std::vector<sptr<CellInformation>> & cells)1092 int32_t NetworkSearchHandler::GetCellInfoList(std::vector<sptr<CellInformation>> &cells)
1093 {
1094 TELEPHONY_LOGD("NetworkSearchHandler::GetCellInfoList slotId:%{public}d", slotId_);
1095 if (cellInfo_ != nullptr) {
1096 cellInfo_->GetCellInfoList(cells);
1097 return TELEPHONY_ERR_SUCCESS;
1098 }
1099 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1100 }
1101
GetCellLocation()1102 sptr<CellLocation> NetworkSearchHandler::GetCellLocation()
1103 {
1104 TELEPHONY_LOGD("NetworkSearchHandler::GetCellLocation slotId:%{public}d", slotId_);
1105 if (cellInfo_ != nullptr) {
1106 return cellInfo_->GetCellLocation();
1107 }
1108 return nullptr;
1109 }
1110
TimezoneRefresh()1111 void NetworkSearchHandler::TimezoneRefresh()
1112 {
1113 TELEPHONY_LOGD("NetworkSearchHandler::TimezoneRefresh slotId:%{public}d", slotId_);
1114 if (nitzUpdate_ != nullptr) {
1115 nitzUpdate_->ProcessTimeZone();
1116 }
1117 }
1118
SendUpdateCellLocationRequest()1119 int32_t NetworkSearchHandler::SendUpdateCellLocationRequest()
1120 {
1121 std::vector<sptr<CellInformation>> cells;
1122 if (cellInfo_ != nullptr) {
1123 cellInfo_->GetCellInfoList(cells);
1124 }
1125 uint32_t curTime = static_cast<uint32_t>(time(0));
1126 if ((curTime < cellRequestMinInterval_ + lastCellRequestTime_) && cells.size() != 0) {
1127 TELEPHONY_LOGE("NetworkSearchHandler::SendUpdateCellLocationRequest interval is too short");
1128 return TELEPHONY_ERR_SUCCESS;
1129 }
1130 TELEPHONY_LOGD("NetworkSearchHandler::SendUpdateCellLocationRequest slotId:%{public}d", slotId_);
1131 std::shared_ptr<ITelRilManager> telRilManager = telRilManager_.lock();
1132 auto event = AppExecFwk::InnerEvent::Get(RadioEvent::RADIO_GET_CURRENT_CELL_INFO);
1133 if (event != nullptr && telRilManager != nullptr) {
1134 lastCellRequestTime_ = curTime;
1135 event->SetOwner(shared_from_this());
1136 telRilManager->GetCurrentCellInfo(slotId_, event);
1137 }
1138 return TELEPHONY_ERR_SUCCESS;
1139 }
1140
UpdateCellLocation(int32_t techType,int32_t cellId,int32_t lac)1141 void NetworkSearchHandler::UpdateCellLocation(int32_t techType, int32_t cellId, int32_t lac)
1142 {
1143 TELEPHONY_LOGD("NetworkSearchHandler::UpdateCellLocation slotId:%{public}d", slotId_);
1144 if (cellInfo_ != nullptr) {
1145 cellInfo_->UpdateCellLocation(techType, cellId, lac);
1146 }
1147 }
1148
GetPhoneType()1149 PhoneType NetworkSearchHandler::GetPhoneType()
1150 {
1151 TELEPHONY_LOGD("NetworkSearchHandler::GetPhoneType");
1152 if (radioInfo_ != nullptr) {
1153 return radioInfo_->GetPhoneType();
1154 }
1155 return PhoneType::PHONE_TYPE_IS_NONE;
1156 }
1157
RadioChannelConfigInfo(const AppExecFwk::InnerEvent::Pointer & event)1158 void NetworkSearchHandler::RadioChannelConfigInfo(const AppExecFwk::InnerEvent::Pointer &event)
1159 {
1160 if (event == nullptr) {
1161 TELEPHONY_LOGE("NetworkSearchHandler::RadioChannelConfigInfo event is nullptr!");
1162 return;
1163 }
1164 if (networkRegister_ != nullptr) {
1165 networkRegister_->ProcessChannelConfigInfo(event);
1166 }
1167 TELEPHONY_LOGD("NetworkSearchHandler::RadioChannelConfigInfo slotId:%{public}d", slotId_);
1168 }
1169
DcPhysicalLinkActiveUpdate(const AppExecFwk::InnerEvent::Pointer & event)1170 void NetworkSearchHandler::DcPhysicalLinkActiveUpdate(const AppExecFwk::InnerEvent::Pointer &event)
1171 {
1172 if (event == nullptr) {
1173 return;
1174 }
1175 bool isActive = (event->GetParam() == 1);
1176 if (networkRegister_ != nullptr) {
1177 networkRegister_->DcPhysicalLinkActiveUpdate(isActive);
1178 }
1179 TELEPHONY_LOGI("NetworkSearchHandler::DcPhysicalLinkActiveUpdate slotId:%{public}d active:%{public}s", slotId_,
1180 isActive ? "true" : "false");
1181 }
1182
NotifyStateChange(const AppExecFwk::InnerEvent::Pointer & event)1183 void NetworkSearchHandler::NotifyStateChange(const AppExecFwk::InnerEvent::Pointer &event)
1184 {
1185 TELEPHONY_LOGI("NetworkSearchHandler::NotifyStateChange slotId:%{public}d", slotId_);
1186 if (event == nullptr) {
1187 TELEPHONY_LOGE("NetworkSearchHandler::NotifyStateChange event is nullptr!");
1188 return;
1189 }
1190 if (networkRegister_ == nullptr) {
1191 TELEPHONY_LOGE("NetworkSearchHandler::NotifyStateChange networkRegister_ is nullptr!");
1192 return;
1193 }
1194 networkRegister_->NotifyStateChange();
1195 }
1196
HandleDelayNotifyEvent(const AppExecFwk::InnerEvent::Pointer & event)1197 void NetworkSearchHandler::HandleDelayNotifyEvent(const AppExecFwk::InnerEvent::Pointer &event)
1198 {
1199 TELEPHONY_LOGI("NetworkSearchHandler::HandleDelayNotifyEvent slotId:%{public}d", slotId_);
1200 if (event == nullptr) {
1201 TELEPHONY_LOGE("NetworkSearchHandler::NotifyStateChange event is nullptr!");
1202 return;
1203 }
1204 if (networkRegister_ == nullptr) {
1205 TELEPHONY_LOGE("NetworkSearchHandler::NotifyStateChange networkRegister_ is nullptr!");
1206 return;
1207 }
1208 RevertLastTechnology();
1209 RadioOnState();
1210 }
1211
HandleRrcStateChanged(int32_t status)1212 int32_t NetworkSearchHandler::HandleRrcStateChanged(int32_t status)
1213 {
1214 TELEPHONY_LOGI("NetworkSearchHandler::HandleRrcStateChanged slotId:%{public}d", slotId_);
1215 if (networkRegister_ == nullptr) {
1216 TELEPHONY_LOGE("NetworkSearchHandler::HandleRrcStateChanged networkRegister_ is nullptr!");
1217 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1218 }
1219 networkRegister_->HandleRrcStateChanged(status);
1220 return TELEPHONY_ERR_SUCCESS;
1221 }
1222
RevertLastTechnology()1223 int32_t NetworkSearchHandler::RevertLastTechnology()
1224 {
1225 TELEPHONY_LOGI("NetworkSearchHandler::RevertLastTechnology slotId:%{public}d", slotId_);
1226 if (networkRegister_ == nullptr) {
1227 TELEPHONY_LOGE("NetworkSearchHandler::RevertLastTechnology networkRegister_ is nullptr!");
1228 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1229 }
1230 networkRegister_->RevertLastTechnology();
1231 return TELEPHONY_ERR_SUCCESS;
1232 }
1233
UpdateImsServiceStatus(const AppExecFwk::InnerEvent::Pointer & event)1234 void NetworkSearchHandler::UpdateImsServiceStatus(const AppExecFwk::InnerEvent::Pointer &event)
1235 {
1236 auto networkSearchManager = networkSearchManager_.lock();
1237 if (event == nullptr) {
1238 TELEPHONY_LOGE("UpdateImsServiceStatus event is null slotId:%{public}d", slotId_);
1239 return;
1240 }
1241 std::shared_ptr<ImsServiceStatus> imsServiceStatus = event->GetSharedObject<ImsServiceStatus>();
1242 if (imsServiceStatus == nullptr) {
1243 TELEPHONY_LOGE("UpdateImsServiceStatus imsServiceStatus is null slotId:%{public}d", slotId_);
1244 return;
1245 }
1246 std::shared_ptr<NetworkSearchState> networkSearchState = networkSearchManager->GetNetworkSearchState(slotId_);
1247 if (networkSearchState != nullptr) {
1248 networkSearchState->SetImsServiceStatus(*imsServiceStatus);
1249 }
1250 TELEPHONY_LOGD("NetworkSearchHandler::UpdateImsServiceStatus slotId:%{public}d", slotId_);
1251 }
1252
UpdateImsRegisterState(const AppExecFwk::InnerEvent::Pointer & event)1253 void NetworkSearchHandler::UpdateImsRegisterState(const AppExecFwk::InnerEvent::Pointer &event)
1254 {
1255 auto networkSearchManager = networkSearchManager_.lock();
1256 if (event == nullptr) {
1257 TELEPHONY_LOGE("UpdateImsRegisterState event is null slotId:%{public}d", slotId_);
1258 return;
1259 }
1260 auto registerInfo = event->GetSharedObject<int32_t>();
1261 if (registerInfo == nullptr) {
1262 TELEPHONY_LOGE("UpdateImsRegisterState registerInfo is null slotId:%{public}d", slotId_);
1263 return;
1264 }
1265 bool isRegister = (*registerInfo == 1);
1266 std::shared_ptr<NetworkSearchState> networkSearchState = networkSearchManager->GetNetworkSearchState(slotId_);
1267 if (networkSearchState != nullptr) {
1268 networkSearchState->SetImsStatus(isRegister);
1269 }
1270 TELEPHONY_LOGI("NetworkSearchHandler::UpdateImsRegisterState slotId:%{public}d isRegister:%{public}s", slotId_,
1271 isRegister ? "true" : "false");
1272 }
1273
RadioGetBasebandVersion(const AppExecFwk::InnerEvent::Pointer & event)1274 void NetworkSearchHandler::RadioGetBasebandVersion(const AppExecFwk::InnerEvent::Pointer &event)
1275 {
1276 if (event == nullptr) {
1277 TELEPHONY_LOGE("NetworkSearchHandler::RadioGetBasebandVersion event is nullptr!");
1278 return;
1279 }
1280 TELEPHONY_LOGD("RadioGetBasebandVersion start slotId:%{public}d", slotId_);
1281 if (radioInfo_ == nullptr) {
1282 TELEPHONY_LOGE("RadioGetBasebandVersion RadioInfo is null slotId:%{public}d", slotId_);
1283 return;
1284 }
1285 radioInfo_->ProcessGetBasebandVersion(event);
1286 }
1287
SetNrOptionModeResponse(const AppExecFwk::InnerEvent::Pointer & event)1288 void NetworkSearchHandler::SetNrOptionModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
1289 {
1290 if (event == nullptr) {
1291 TELEPHONY_LOGE("NetworkSearchHandler::SetNrOptionModeResponse event is nullptr!");
1292 return;
1293 }
1294 TELEPHONY_LOGD("SetNrOptionModeResponse start slotId:%{public}d", slotId_);
1295 if (radioInfo_ == nullptr) {
1296 TELEPHONY_LOGE("SetNrOptionModeResponse RadioInfo is null slotId:%{public}d", slotId_);
1297 return;
1298 }
1299 radioInfo_->ProcessSetNrOptionMode(event);
1300 }
1301
GetNrOptionModeResponse(const AppExecFwk::InnerEvent::Pointer & event)1302 void NetworkSearchHandler::GetNrOptionModeResponse(const AppExecFwk::InnerEvent::Pointer &event)
1303 {
1304 if (event == nullptr) {
1305 TELEPHONY_LOGE("NetworkSearchHandler::GetNrOptionModeResponse event is nullptr!");
1306 return;
1307 }
1308 TELEPHONY_LOGD("GetNrOptionModeResponse start slotId:%{public}d", slotId_);
1309 if (radioInfo_ == nullptr) {
1310 TELEPHONY_LOGE("GetNrOptionModeResponse RadioInfo is null slotId:%{public}d", slotId_);
1311 return;
1312 }
1313 radioInfo_->ProcessGetNrOptionMode(event);
1314 }
1315
RadioGetRrcConnectionState(const AppExecFwk::InnerEvent::Pointer & event)1316 void NetworkSearchHandler::RadioGetRrcConnectionState(const AppExecFwk::InnerEvent::Pointer &event)
1317 {
1318 if (event == nullptr) {
1319 TELEPHONY_LOGE("NetworkSearchHandler::RadioGetRrcConnectionState event is nullptr!");
1320 return;
1321 }
1322 TELEPHONY_LOGD("RadioGetRrcConnectionState start slotId:%{public}d", slotId_);
1323 if (radioInfo_ == nullptr) {
1324 TELEPHONY_LOGE("RadioGetRrcConnectionState RadioInfo is null slotId:%{public}d", slotId_);
1325 return;
1326 }
1327 radioInfo_->ProcessGetRrcConnectionState(event);
1328 }
1329
RadioVoiceTechChange(const AppExecFwk::InnerEvent::Pointer & event)1330 void NetworkSearchHandler::RadioVoiceTechChange(const AppExecFwk::InnerEvent::Pointer &event)
1331 {
1332 if (event == nullptr) {
1333 TELEPHONY_LOGE("NetworkSearchHandler::RadioVoiceTechChange event is nullptr!");
1334 return;
1335 }
1336 if (radioInfo_ != nullptr) {
1337 radioInfo_->ProcessVoiceTechChange(event);
1338 }
1339 TELEPHONY_LOGD("NetworkSearchHandler::RadioVoiceTechChange");
1340 }
1341
GetNrSsbIdResponse(const AppExecFwk::InnerEvent::Pointer & event)1342 void NetworkSearchHandler::GetNrSsbIdResponse(const AppExecFwk::InnerEvent::Pointer &event)
1343 {
1344 TELEPHONY_LOGD("Start slotId:%{public}d", slotId_);
1345 if (event == nullptr) {
1346 TELEPHONY_LOGE("Event is nullptr!");
1347 return;
1348 }
1349 if (nrSsbInfo_ == nullptr) {
1350 TELEPHONY_LOGE("NrSsbInfo is null");
1351 return;
1352 }
1353 if (nrSsbInfo_->ProcessGetNrSsbId(event)) {
1354 SyncGetSsbInfoResponse();
1355 }
1356 }
1357
SyncGetSsbInfoResponse()1358 void NetworkSearchHandler::SyncGetSsbInfoResponse()
1359 {
1360 std::unique_lock<std::mutex> lck(NetworkSearchManager::ctx_);
1361 NetworkSearchManager::ssbResponseReady_ = true;
1362 TELEPHONY_LOGD("ssbResponseReady_ = %{public}d", NetworkSearchManager::ssbResponseReady_);
1363 NetworkSearchManager::cv_.notify_one();
1364 }
1365
GetNrSsbId(const std::shared_ptr<NrSsbInformation> & nrCellSsbIdsInfo)1366 int32_t NetworkSearchHandler::GetNrSsbId(const std::shared_ptr<NrSsbInformation> &nrCellSsbIdsInfo)
1367 {
1368 TELEPHONY_LOGI("SlotId:%{public}d", slotId_);
1369 if (nrSsbInfo_ != nullptr) {
1370 if (nrSsbInfo_->FillNrSsbIdInformation(nrCellSsbIdsInfo)) {
1371 return TELEPHONY_ERR_SUCCESS;
1372 }
1373 }
1374 return TELEPHONY_ERR_LOCAL_PTR_NULL;
1375 }
1376
AutoTimeChange(const AppExecFwk::InnerEvent::Pointer &)1377 void NetworkSearchHandler::AutoTimeChange(const AppExecFwk::InnerEvent::Pointer &)
1378 {
1379 TELEPHONY_LOGD("NetworkSearchHandler::AutoTimeChange");
1380 if (nitzUpdate_ != nullptr) {
1381 nitzUpdate_->AutoTimeChange();
1382 }
1383 }
1384
AutoTimeZoneChange(const AppExecFwk::InnerEvent::Pointer &)1385 void NetworkSearchHandler::AutoTimeZoneChange(const AppExecFwk::InnerEvent::Pointer &)
1386 {
1387 TELEPHONY_LOGD("NetworkSearchHandler::AutoTimeZoneChange");
1388 if (nitzUpdate_ != nullptr) {
1389 nitzUpdate_->AutoTimeZoneChange();
1390 }
1391 }
1392
AirplaneModeChange(const AppExecFwk::InnerEvent::Pointer &)1393 void NetworkSearchHandler::AirplaneModeChange(const AppExecFwk::InnerEvent::Pointer &)
1394 {
1395 TELEPHONY_LOGD("NetworkSearchHandler::AirplaneModeChange");
1396 if (radioInfo_ != nullptr) {
1397 radioInfo_->AirplaneModeChange();
1398 }
1399 }
1400
RadioResidentNetworkChange(const AppExecFwk::InnerEvent::Pointer & event)1401 void NetworkSearchHandler::RadioResidentNetworkChange(const AppExecFwk::InnerEvent::Pointer &event)
1402 {
1403 if (event == nullptr) {
1404 TELEPHONY_LOGE("NetworkSearchHandler::RadioResidentNetworkChange event is nullptr!");
1405 return;
1406 }
1407 auto networkSearchManager = networkSearchManager_.lock();
1408 if (networkSearchManager == nullptr) {
1409 TELEPHONY_LOGE("RadioResidentNetworkChange networkSearchManager is nullptr");
1410 return;
1411 }
1412 auto object = event->GetSharedObject<std::string>();
1413 if (object == nullptr) {
1414 TELEPHONY_LOGE("NetworkSearchHandler::RadioResidentNetworkChange object is nullptr!");
1415 networkSearchManager->SetResidentNetworkNumeric(slotId_, "");
1416 return;
1417 }
1418 std::string plmn = *object;
1419 networkSearchManager->SetResidentNetworkNumeric(slotId_, plmn);
1420 for (int32_t slotId = 0; slotId < SIM_SLOT_COUNT; slotId++) {
1421 if (networkSearchManager->GetCsRegState(slotId) ==
1422 static_cast<int32_t>(RegServiceState::REG_STATE_IN_SERVICE) ||
1423 networkSearchManager->GetPsRegState(slotId) ==
1424 static_cast<int32_t>(RegServiceState::REG_STATE_IN_SERVICE)) {
1425 TELEPHONY_LOGE("RadioResidentNetworkChange RegState is in service");
1426 return;
1427 }
1428 }
1429 std::string countryCode = "";
1430 if (plmn.length() >= MCC_LEN) {
1431 std::string mcc = plmn.substr(0, MCC_LEN);
1432 int32_t value = 0;
1433 if (StrToInt(mcc, value)) {
1434 countryCode = MccPool::MccCountryCode(value);
1435 } else {
1436 TELEPHONY_LOGE("RadioResidentNetworkChange parse Failed!! slotId:%{public}d", slotId_);
1437 }
1438 }
1439 if (countryCode.empty()) {
1440 TELEPHONY_LOGE("RadioResidentNetworkChange countryCode is empty");
1441 return;
1442 }
1443 TELEPHONY_LOGI("RadioResidentNetworkChange: update countryCode[%{public}s]", countryCode.c_str());
1444 if (TELEPHONY_EXT_WRAPPER.updateCountryCodeExt_ != nullptr) {
1445 TELEPHONY_EXT_WRAPPER.updateCountryCodeExt_(slotId_, countryCode.c_str());
1446 } else {
1447 if (nitzUpdate_ != nullptr) {
1448 nitzUpdate_->UpdateCountryCode(countryCode);
1449 }
1450 }
1451 }
1452
SatelliteStatusChanged(const AppExecFwk::InnerEvent::Pointer & event)1453 void NetworkSearchHandler::SatelliteStatusChanged(const AppExecFwk::InnerEvent::Pointer &event)
1454 {
1455 if (event == nullptr) {
1456 TELEPHONY_LOGE("NetworkSearchHandler::RadioResidentNetworkChange event is nullptr!");
1457 return;
1458 }
1459 auto satelliteStatus = event->GetSharedObject<SatelliteStatus>();
1460 if (satelliteStatus == nullptr) {
1461 TELEPHONY_LOGE("NetworkSearchHandler::satelliteStatus is nullptr!");
1462 return;
1463 }
1464 if (satelliteStatus->mode == SATELLITE_STATUS_ON) {
1465 std::shared_ptr<SatelliteServiceClient> satelliteClient =
1466 DelayedSingleton<SatelliteServiceClient>::GetInstance();
1467 satelliteClient->SetRadioState(
1468 satelliteStatus->slotId, static_cast<int32_t>(ModemPowerState::CORE_SERVICE_POWER_ON), 0);
1469 }
1470 }
1471
SetCellRequestMinInterval(uint32_t minInterval)1472 void NetworkSearchHandler::SetCellRequestMinInterval(uint32_t minInterval)
1473 {
1474 cellRequestMinInterval_ = minInterval;
1475 }
1476
IsSatelliteSupported() const1477 int32_t NetworkSearchHandler::IsSatelliteSupported() const
1478 {
1479 char satelliteSupported[SYSPARA_SIZE] = { 0 };
1480 GetParameter(TEL_SATELLITE_SUPPORTED, SATELLITE_DEFAULT_VALUE, satelliteSupported, SYSPARA_SIZE);
1481 TELEPHONY_LOGI("satelliteSupported is %{public}s", satelliteSupported);
1482 return std::atoi(satelliteSupported);
1483 }
1484
IsSatelliteOn() const1485 bool NetworkSearchHandler::IsSatelliteOn() const
1486 {
1487 bool isSatelliteOn = CoreManagerInner::GetInstance().IsSatelliteEnabled();
1488 bool isSupportSatellite = (IsSatelliteSupported() == static_cast<int32_t>(SatelliteValue::SATELLITE_SUPPORTED));
1489 bool isSatelliteState = isSatelliteOn && isSupportSatellite;
1490 TELEPHONY_LOGI("NetworkSearchHandler::IsSatelliteOn %{public}d", isSatelliteState);
1491 return isSatelliteState;
1492 }
1493
ClearSignalAndCellInfoList() const1494 void NetworkSearchHandler::ClearSignalAndCellInfoList() const
1495 {
1496 if (signalInfo_ != nullptr) {
1497 TELEPHONY_LOGD("reset signal info slotId: %{public}d", slotId_);
1498 signalInfo_->Reset();
1499 std::vector<sptr<SignalInformation>> signals;
1500 signalInfo_->GetSignalInfoList(signals);
1501 if (TELEPHONY_EXT_WRAPPER.sortSignalInfoListExt_ != nullptr) {
1502 TELEPHONY_EXT_WRAPPER.sortSignalInfoListExt_(slotId_, signals);
1503 }
1504 DelayedSingleton<NetworkSearchNotify>::GetInstance()->NotifySignalInfoUpdated(slotId_, signals);
1505 }
1506 if (cellInfo_ != nullptr) {
1507 cellInfo_->ClearCellInfoList();
1508 }
1509 }
1510
SystemAbilityStatusChangeListener(std::shared_ptr<OperatorName> & operatorName)1511 NetworkSearchHandler::SystemAbilityStatusChangeListener::SystemAbilityStatusChangeListener(
1512 std::shared_ptr<OperatorName> &operatorName) : opName_(operatorName)
1513 {}
1514
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1515 void NetworkSearchHandler::SystemAbilityStatusChangeListener::OnAddSystemAbility(
1516 int32_t systemAbilityId, const std::string& deviceId)
1517 {
1518 switch (systemAbilityId) {
1519 case COMMON_EVENT_SERVICE_ID: {
1520 if (opName_ == nullptr) {
1521 TELEPHONY_LOGE("OnAddSystemAbility COMMON_EVENT_SERVICE_ID opName_ is nullptr");
1522 return;
1523 }
1524 opName_->NotifySpnChanged(true);
1525 bool subscribeResult = EventFwk::CommonEventManager::SubscribeCommonEvent(opName_);
1526 bool settingsResult = EventFwk::CommonEventManager::SubscribeCommonEvent(
1527 SettingUtils::GetInstance()->GetCommonEventSubscriber());
1528 TELEPHONY_LOGI("NetworkSearchHandler::OnAddSystemAbility subscribeResult = %{public}d, %{public}d",
1529 subscribeResult, settingsResult);
1530 break;
1531 }
1532 case DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID:
1533 TELEPHONY_LOGI("NetworkSearchHandler::OnAddSystemAbility DISTRIBUTED_KV_DATA_SERVICE_ABILITY_ID");
1534 SettingUtils::GetInstance()->UpdateDdsState(true);
1535 break;
1536 default:
1537 TELEPHONY_LOGE("NetworkSearchHandler::OnAddSystemAbility unknown sa id %{public}d", systemAbilityId);
1538 }
1539 }
1540
OnRemoveSystemAbility(int32_t systemAbilityId,const std::string & deviceId)1541 void NetworkSearchHandler::SystemAbilityStatusChangeListener::OnRemoveSystemAbility(
1542 int32_t systemAbilityId, const std::string& deviceId)
1543 {
1544 if (systemAbilityId != COMMON_EVENT_SERVICE_ID) {
1545 TELEPHONY_LOGE("systemAbilityId is not COMMON_EVENT_SERVICE_ID");
1546 return;
1547 }
1548 if (opName_ == nullptr) {
1549 TELEPHONY_LOGE("OnRemoveSystemAbility COMMON_EVENT_SERVICE_ID opName_ is nullptr");
1550 return;
1551 }
1552 bool subscribeResult = CommonEventManager::UnSubscribeCommonEvent(opName_);
1553 TELEPHONY_LOGI("NetworkSearchHandler::OnRemoveSystemAbility subscribeResult = %{public}d", subscribeResult);
1554 }
1555
IsPowerOnPrimaryRadioWhenNoSim() const1556 bool NetworkSearchHandler::IsPowerOnPrimaryRadioWhenNoSim() const
1557 {
1558 TELEPHONY_LOGD("Start to check if power on primary modem's radio when sim slots are empty");
1559 std::shared_ptr<NetworkSearchManager> nsm = networkSearchManager_.lock();
1560 if (nsm == nullptr) {
1561 TELEPHONY_LOGE("get networkSearchManager is failed");
1562 return false;
1563 }
1564 auto simManager = nsm->GetSimManager();
1565 if (simManager == nullptr) {
1566 TELEPHONY_LOGE("get simManager failed");
1567 return false;
1568 }
1569 int32_t primarySlotId = INVALID_SLOT_ID;
1570 simManager->GetPrimarySlotId(primarySlotId);
1571 if (primarySlotId != INVALID_SLOT_ID && primarySlotId == slotId_) {
1572 TELEPHONY_LOGD("primarySlotId = %{public}d, send radio on request", primarySlotId);
1573 return true;
1574 }
1575 return false;
1576 }
1577
ProcessSignalIntensity(int32_t slotId,const Rssi & signalIntensity)1578 void NetworkSearchHandler::ProcessSignalIntensity(int32_t slotId, const Rssi &signalIntensity)
1579 {
1580 Rssi *s = const_cast<Rssi*>(&signalIntensity);
1581 if (signalInfo_ != nullptr) {
1582 signalInfo_->ProcessSignalIntensity(slotId, s);
1583 }
1584 }
1585 } // namespace Telephony
1586 } // namespace OHOS
1587