1 /*
2 * Copyright (C) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "operator_name.h"
17
18 #include <common_event.h>
19 #include <common_event_manager.h>
20
21 #include "common_event_support.h"
22 #include "core_manager_inner.h"
23 #include "hril_network_parcel.h"
24 #include "network_search_manager.h"
25 #include "operator_config_types.h"
26 #include "operator_name_utils.h"
27 #include "resource_utils.h"
28 #include "telephony_log_wrapper.h"
29 using namespace OHOS::AppExecFwk;
30 using namespace OHOS::EventFwk;
31
32 namespace OHOS {
33 namespace Telephony {
34 namespace {
35 const int32_t FORMAT_IDX_SPN_CS = 0;
36 const int32_t PNN_CUST_STRING_SIZE = 2;
37 const int32_t OPL_CUST_STRING_SIZE = 4;
38 } // namespace
39
OperatorName(const EventFwk::CommonEventSubscribeInfo & sp,std::shared_ptr<NetworkSearchState> networkSearchState,std::shared_ptr<ISimManager> simManager,std::weak_ptr<NetworkSearchManager> networkSearchManager,int32_t slotId)40 OperatorName::OperatorName(const EventFwk::CommonEventSubscribeInfo &sp,
41 std::shared_ptr<NetworkSearchState> networkSearchState, std::shared_ptr<ISimManager> simManager,
42 std::weak_ptr<NetworkSearchManager> networkSearchManager, int32_t slotId)
43 : CommonEventSubscriber(sp), networkSearchState_(networkSearchState), simManager_(simManager),
44 networkSearchManager_(networkSearchManager), slotId_(slotId)
45 {
46 std::vector<std::string> vecSpnFormats;
47 ResourceUtils::Get().GetStringArrayValueByName(ResourceUtils::SPN_FORMATS, vecSpnFormats);
48 if (vecSpnFormats.size() > FORMAT_IDX_SPN_CS) {
49 csSpnFormat_ = vecSpnFormats[FORMAT_IDX_SPN_CS];
50 }
51 UpdateOperatorConfig();
52 }
53
OnReceiveEvent(const EventFwk::CommonEventData & data)54 void OperatorName::OnReceiveEvent(const EventFwk::CommonEventData &data)
55 {
56 const AAFwk::Want &want = data.GetWant();
57 std::string action = want.GetAction();
58 if (action == CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED) {
59 int32_t slotId = want.GetIntParam("slotId", 0);
60 if (slotId_ != slotId) {
61 return;
62 }
63 UpdateOperatorConfig();
64 sptr<NetworkState> networkState = GetNetworkStatus();
65 if (networkState != nullptr && networkState->GetRegStatus() == RegServiceState::REG_STATE_IN_SERVICE) {
66 NotifySpnChanged();
67 }
68 } else if (action == CommonEventSupport::COMMON_EVENT_LOCALE_CHANGED) {
69 TELEPHONY_LOGI("locale changed Slot%{public}d", slotId_);
70 TrySetLongOperatorNameWithTranslation();
71 auto networkSearchManager = networkSearchManager_.lock();
72 if (networkSearchManager == nullptr) {
73 TELEPHONY_LOGE("networkSearchManager is nullptr slotId:%{public}d", slotId_);
74 return;
75 }
76 networkSearchManager->decMsgNum(slotId_);
77 if (networkSearchManager->CheckIsNeedNotify(slotId_)) {
78 networkSearchManager->ProcessNotifyStateChangeEvent(slotId_);
79 }
80 } else {
81 TELEPHONY_LOGI("OperatorName::OnReceiveEvent Slot%{public}d: action=%{public}s code=%{public}d", slotId_,
82 action.c_str(), data.GetCode());
83 }
84 }
85
HandleOperatorInfo(const AppExecFwk::InnerEvent::Pointer & event)86 void OperatorName::HandleOperatorInfo(const AppExecFwk::InnerEvent::Pointer &event)
87 {
88 auto networkSearchManager = networkSearchManager_.lock();
89 if (networkSearchManager == nullptr) {
90 TELEPHONY_LOGE("OperatorName::HandleOperatorInfo networkSearchManager is nullptr slotId:%{public}d", slotId_);
91 return;
92 }
93 if (event == nullptr) {
94 TELEPHONY_LOGE("event is nullptr slotId:%{public}d", slotId_);
95 return;
96 }
97 std::shared_ptr<OperatorInfoResult> operatorInfoResult = event->GetSharedObject<OperatorInfoResult>();
98 if (operatorInfoResult == nullptr) {
99 TELEPHONY_LOGE("operatorInfoResult is nullptr slotId:%{public}d", slotId_);
100 return;
101 }
102 if (operatorInfoResult->flag != networkSearchManager->GetSerialNum(slotId_) &&
103 operatorInfoResult->flag != NetworkSearchManagerInner::SERIAL_NUMBER_EXEMPT) {
104 TELEPHONY_LOGI("Aborting outdated operator info event slotId:%{public}d", slotId_);
105 return;
106 }
107 PhoneType type = networkSearchManager->GetPhoneType(slotId_);
108 if (type == PhoneType::PHONE_TYPE_IS_GSM) {
109 GsmOperatorInfo(event);
110 } else if (type == PhoneType::PHONE_TYPE_IS_CDMA) {
111 CdmaOperatorInfo(event);
112 } else {
113 TELEPHONY_LOGE("OperatorName::HandleOperatorInfo phone type:%{public}d invalid", type);
114 }
115 networkSearchManager->decMsgNum(slotId_);
116 if (networkSearchManager->CheckIsNeedNotify(slotId_)) {
117 networkSearchManager->ProcessNotifyStateChangeEvent(slotId_);
118 }
119
120 NotifySpnChanged();
121 networkSearchManager->TriggerTimezoneRefresh(slotId_);
122 }
123
GsmOperatorInfo(const AppExecFwk::InnerEvent::Pointer & event)124 void OperatorName::GsmOperatorInfo(const AppExecFwk::InnerEvent::Pointer &event)
125 {
126 if (event == nullptr) {
127 TELEPHONY_LOGE("OperatorName::GsmOperatorInfo event is nullptr slotId:%{public}d", slotId_);
128 return;
129 }
130 std::string longName = "";
131 std::string shortName = "";
132 std::string numeric = "";
133 std::shared_ptr<OperatorInfoResult> operatorInfoResult = event->GetSharedObject<OperatorInfoResult>();
134 if (operatorInfoResult != nullptr) {
135 longName = operatorInfoResult->longName;
136 shortName = operatorInfoResult->shortName;
137 numeric = operatorInfoResult->numeric;
138 UpdateOperatorLongName(longName, numeric);
139 }
140 TELEPHONY_LOGI(
141 "OperatorName::GsmOperatorInfo longName : %{public}s, shortName : %{public}s, numeric : %{public}s "
142 "slotId:%{public}d",
143 longName.c_str(), shortName.c_str(), numeric.c_str(), slotId_);
144 if (networkSearchState_ != nullptr) {
145 networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_CS);
146 networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_PS);
147 }
148 }
149
CdmaOperatorInfo(const AppExecFwk::InnerEvent::Pointer & event)150 void OperatorName::CdmaOperatorInfo(const AppExecFwk::InnerEvent::Pointer &event)
151 {
152 if (event == nullptr) {
153 TELEPHONY_LOGE("OperatorName::CdmaOperatorInfo event is nullptr slotId:%{public}d", slotId_);
154 return;
155 }
156 std::string longName = "";
157 std::string shortName = "";
158 std::string numeric = "";
159 std::shared_ptr<OperatorInfoResult> operatorInfoResult = event->GetSharedObject<OperatorInfoResult>();
160 if (operatorInfoResult != nullptr) {
161 longName = operatorInfoResult->longName;
162 shortName = operatorInfoResult->shortName;
163 numeric = operatorInfoResult->numeric;
164 UpdateOperatorLongName(longName, numeric);
165 }
166 TELEPHONY_LOGI(
167 "OperatorName::CdmaOperatorInfo longName : %{public}s, shortName : %{public}s, numeric : %{public}s "
168 "slotId:%{public}d",
169 longName.c_str(), shortName.c_str(), numeric.c_str(), slotId_);
170 if (networkSearchState_ != nullptr) {
171 networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_CS);
172 networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_PS);
173 }
174 }
175
GetNetworkStatus()176 sptr<NetworkState> OperatorName::GetNetworkStatus()
177 {
178 if (networkSearchState_ != nullptr) {
179 std::unique_ptr<NetworkState> networkState = networkSearchState_->GetNetworkStatus();
180 if (networkState != nullptr) {
181 networkState_ = networkState.release();
182 return networkState_;
183 }
184 }
185 TELEPHONY_LOGE("OperatorName::GetNetworkStatus networkState is nullptr slotId:%{public}d", slotId_);
186 networkState_ = nullptr;
187 return networkState_;
188 }
189
190 /**
191 * 3GPP TS 51.011 V5.0.0(2001-12) 10.3.11
192 */
NotifySpnChanged()193 void OperatorName::NotifySpnChanged()
194 {
195 auto networkSearchManager = networkSearchManager_.lock();
196 if (networkSearchManager == nullptr) {
197 TELEPHONY_LOGE("OperatorName::NotifySpnChanged networkSearchManager is nullptr slotId:%{public}d", slotId_);
198 return;
199 }
200 TELEPHONY_LOGI("OperatorName::NotifySpnChanged slotId:%{public}d", slotId_);
201 std::string netPlmn = "";
202 std::string simPlmn = "";
203 std::string domesticSpn = "";
204 RegServiceState regStatus = RegServiceState::REG_STATE_UNKNOWN;
205 sptr<NetworkState> networkState = GetNetworkStatus();
206 if (networkState != nullptr) {
207 regStatus = networkState->GetRegStatus();
208 netPlmn = networkState->GetPlmnNumeric();
209 }
210 if (simManager_ != nullptr) {
211 std::u16string operatorNumeric = u"";
212 simManager_->GetSimOperatorNumeric(slotId_, operatorNumeric);
213 simPlmn = Str16ToStr8(operatorNumeric);
214 }
215 if (isDomesticRoaming(simPlmn, netPlmn)) {
216 domesticSpn = GetCustomName(simPlmn);
217 }
218
219 if (networkSearchManager->GetPhoneType(slotId_) == PhoneType::PHONE_TYPE_IS_GSM) {
220 NotifyGsmSpnChanged(regStatus, networkState, domesticSpn);
221 } else if (networkSearchManager->GetPhoneType(slotId_) == PhoneType::PHONE_TYPE_IS_CDMA) {
222 NotifyCdmaSpnChanged(regStatus, networkState, domesticSpn);
223 }
224 }
225
UpdatePlmn(RegServiceState regStatus,sptr<NetworkState> & networkState,int32_t spnRule,std::string & plmn,bool & showPlmn)226 void OperatorName::UpdatePlmn(
227 RegServiceState regStatus, sptr<NetworkState> &networkState, int32_t spnRule, std::string &plmn, bool &showPlmn)
228 {
229 if (networkState != nullptr) {
230 switch (regStatus) {
231 case RegServiceState::REG_STATE_IN_SERVICE:
232 plmn = GetPlmn(networkState, true);
233 showPlmn =
234 !plmn.empty() && ((static_cast<uint32_t>(spnRule) & SpnShowType::SPN_CONDITION_DISPLAY_PLMN) ==
235 SpnShowType::SPN_CONDITION_DISPLAY_PLMN);
236 break;
237 case RegServiceState::REG_STATE_NO_SERVICE:
238 case RegServiceState::REG_STATE_EMERGENCY_ONLY:
239 case RegServiceState::REG_STATE_SEARCH:
240 if (networkState->IsEmergency()) {
241 ResourceUtils::Get().GetStringValueByName(ResourceUtils::EMERGENCY_CALLS_ONLY, plmn);
242 } else {
243 ResourceUtils::Get().GetStringValueByName(ResourceUtils::OUT_OF_SERIVCE, plmn);
244 }
245 showPlmn = true;
246 break;
247 case RegServiceState::REG_STATE_UNKNOWN:
248 case RegServiceState::REG_STATE_POWER_OFF:
249 default:
250 ResourceUtils::Get().GetStringValueByName(ResourceUtils::OUT_OF_SERIVCE, plmn);
251 showPlmn = true;
252 break;
253 }
254 }
255 }
256
UpdateSpn(RegServiceState regStatus,sptr<NetworkState> & networkState,int32_t spnRule,std::string & spn,bool & showSpn)257 void OperatorName::UpdateSpn(
258 RegServiceState regStatus, sptr<NetworkState> &networkState, int32_t spnRule, std::string &spn, bool &showSpn)
259 {
260 if (regStatus == RegServiceState::REG_STATE_IN_SERVICE) {
261 if (enableCust_ && !spnCust_.empty()) {
262 spn = spnCust_;
263 }
264 if (spn.empty()) {
265 std::u16string result = Str8ToStr16("");
266 if (simManager_ != nullptr) {
267 simManager_->GetSimSpn(slotId_, result);
268 }
269 spn = Str16ToStr8(result);
270 }
271 if (!csSpnFormat_.empty()) {
272 spn = NetworkUtils::FormatString(csSpnFormat_, spn.c_str());
273 }
274 showSpn = !spn.empty() && ((static_cast<uint32_t>(spnRule) & SpnShowType::SPN_CONDITION_DISPLAY_SPN) ==
275 SpnShowType::SPN_CONDITION_DISPLAY_SPN);
276 } else {
277 spn = "";
278 showSpn = false;
279 }
280 }
281
NotifyGsmSpnChanged(RegServiceState regStatus,sptr<NetworkState> & networkState,const std::string & domesticSpn)282 void OperatorName::NotifyGsmSpnChanged(
283 RegServiceState regStatus, sptr<NetworkState> &networkState, const std::string &domesticSpn)
284 {
285 if (networkState == nullptr) {
286 TELEPHONY_LOGE("OperatorName::NotifyGsmSpnChanged networkState is nullptr slotId:%{public}d", slotId_);
287 return;
288 }
289 int32_t spnRule = 0;
290 std::string plmn = "";
291 std::string spn = "";
292 bool showPlmn = false;
293 bool showSpn = false;
294 bool roaming = networkState->IsRoaming();
295 if (enableCust_ && displayConditionCust_ != SPN_INVALID) {
296 spnRule = GetCustSpnRule(roaming);
297 } else {
298 std::string numeric = networkState->GetPlmnNumeric();
299 if (simManager_ != nullptr) {
300 spnRule = simManager_->ObtainSpnCondition(slotId_, roaming, numeric);
301 }
302 }
303 UpdatePlmn(regStatus, networkState, spnRule, plmn, showPlmn);
304 UpdateSpn(regStatus, networkState, spnRule, spn, showSpn);
305 TELEPHONY_LOGI(
306 "OperatorName::NotifyGsmSpnChanged showSpn:%{public}d curSpn_:%{public}s spn:%{public}s showPlmn:%{public}d "
307 "curPlmn_:%{public}s plmn:%{public}s slotId:%{public}d",
308 showSpn, curSpn_.c_str(), spn.c_str(), showPlmn, curPlmn_.c_str(), plmn.c_str(), slotId_);
309 if (curSpnRule_ != spnRule || curRegState_ != regStatus || curSpnShow_ != showSpn || curPlmnShow_ != showPlmn ||
310 curSpn_.compare(spn) || curPlmn_.compare(plmn)) {
311 TELEPHONY_LOGI("OperatorName::NotifyGsmSpnChanged start send broadcast slotId:%{public}d...", slotId_);
312 PublishEvent(spnRule, regStatus, showPlmn, plmn, showSpn, spn, domesticSpn);
313 } else {
314 TELEPHONY_LOGI(
315 "OperatorName::NotifyGsmSpnChanged spn no changed, not need to update slotId:%{public}d", slotId_);
316 }
317 }
318
NotifyCdmaSpnChanged(RegServiceState regStatus,sptr<NetworkState> & networkState,const std::string & domesticSpn)319 void OperatorName::NotifyCdmaSpnChanged(
320 RegServiceState regStatus, sptr<NetworkState> &networkState, const std::string &domesticSpn)
321 {
322 if (networkState == nullptr) {
323 TELEPHONY_LOGE("OperatorName::NotifyCdmaSpnChanged networkState is nullptr slotId:%{public}d", slotId_);
324 return;
325 }
326 int32_t spnRule = 0;
327 std::string plmn = "";
328 std::string spn = "";
329 bool showPlmn = false;
330 bool showSpn = false;
331 std::string numeric = networkState->GetPlmnNumeric();
332 if (regStatus == RegServiceState::REG_STATE_IN_SERVICE) {
333 plmn = GetCustomName(numeric);
334 if (plmn.empty()) {
335 plmn = networkState->GetLongOperatorName();
336 }
337 if (!csSpnFormat_.empty()) {
338 plmn = NetworkUtils::FormatString(csSpnFormat_, plmn.c_str());
339 }
340 } else if (regStatus != RegServiceState::REG_STATE_POWER_OFF) {
341 ResourceUtils::Get().GetStringValueByName(ResourceUtils::OUT_OF_SERIVCE, plmn);
342 }
343 showPlmn = !plmn.empty();
344 TELEPHONY_LOGI(
345 "OperatorName::NotifyCdmaSpnChanged showSpn:%{public}d curSpn_:%{public}s spn:%{public}s "
346 "showPlmn:%{public}d curPlmn_:%{public}s plmn:%{public}s slotId:%{public}d",
347 showSpn, curSpn_.c_str(), spn.c_str(), showPlmn, curPlmn_.c_str(), plmn.c_str(), slotId_);
348 if (curSpnRule_ != spnRule || curRegState_ != regStatus || curSpnShow_ != showSpn || curPlmnShow_ != showPlmn ||
349 curSpn_.compare(spn) || curPlmn_.compare(plmn)) {
350 TELEPHONY_LOGI("OperatorName::NotifyCdmaSpnChanged start send broadcast slotId:%{public}d...", slotId_);
351 PublishEvent(spnRule, regStatus, showPlmn, plmn, showSpn, spn, domesticSpn);
352 } else {
353 TELEPHONY_LOGI(
354 "OperatorName::NotifyCdmaSpnChanged spn no changed, not need to update slotId:%{public}d", slotId_);
355 }
356 }
357
PublishEvent(const int32_t rule,const RegServiceState state,const bool showPlmn,const std::string & plmn,const bool showSpn,const std::string & spn,const std::string & domesticSpn)358 void OperatorName::PublishEvent(const int32_t rule, const RegServiceState state, const bool showPlmn,
359 const std::string &plmn, const bool showSpn, const std::string &spn, const std::string &domesticSpn)
360 {
361 Want want;
362 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SPN_INFO_CHANGED);
363 want.SetParam(CUR_SLOT_ID, slotId_);
364 want.SetParam(CUR_PLMN_SHOW, showPlmn);
365 want.SetParam(CUR_PLMN, plmn);
366 want.SetParam(CUR_SPN_SHOW, showSpn);
367 want.SetParam(CUR_SPN, spn);
368 want.SetParam(DOMESTIC_SPN, domesticSpn);
369 CommonEventData data;
370 data.SetWant(want);
371
372 CommonEventPublishInfo publishInfo;
373 publishInfo.SetSticky(true);
374 bool publishResult = CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
375 TELEPHONY_LOGI("OperatorName::PublishEvent result : %{public}d slotId:%{public}d", publishResult, slotId_);
376 if (publishResult) {
377 curRegState_ = state;
378 curSpnRule_ = rule;
379 curSpn_ = spn;
380 curSpnShow_ = showSpn;
381 curPlmn_ = plmn;
382 curPlmnShow_ = showPlmn;
383 }
384 }
385
GetPlmn(const sptr<NetworkState> & networkState,bool longNameRequired)386 std::string OperatorName::GetPlmn(const sptr<NetworkState> &networkState, bool longNameRequired)
387 {
388 if (networkState == nullptr) {
389 TELEPHONY_LOGE("OperatorName::GetPlmn networkState is nullptr slotId:%{public}d", slotId_);
390 return "";
391 }
392 std::string plmn = "";
393 std::string numeric = networkState->GetPlmnNumeric();
394 bool roaming = networkState->IsRoaming();
395 int32_t lac = GetCurrentLac();
396 plmn = GetCustomName(numeric);
397 if (plmn.empty()) {
398 plmn = GetCustEons(numeric, lac, roaming, longNameRequired);
399 }
400 if (plmn.empty()) {
401 plmn = GetEons(numeric, lac, longNameRequired);
402 }
403 if (plmn.empty()) {
404 plmn = networkState->GetLongOperatorName();
405 }
406 TELEPHONY_LOGD(
407 "OperatorName::GetPlmn lac:%{public}d, numeric:%{public}s, longNameRequired:%{public}d, plmn:%{public}s", lac,
408 numeric.c_str(), longNameRequired, plmn.c_str());
409 return plmn;
410 }
411
GetEons(const std::string & numeric,int32_t lac,bool longNameRequired)412 std::string OperatorName::GetEons(const std::string &numeric, int32_t lac, bool longNameRequired)
413 {
414 if (simManager_ == nullptr) {
415 TELEPHONY_LOGE("OperatorName::GetEons simManager_ is nullptr slotId:%{public}d", slotId_);
416 return "";
417 }
418 return Str16ToStr8(simManager_->GetSimEons(slotId_, numeric, lac, longNameRequired));
419 }
420
GetCustSpnRule(bool roaming)421 unsigned int OperatorName::GetCustSpnRule(bool roaming)
422 {
423 unsigned int cond = 0;
424 if (displayConditionCust_ <= SPN_INVALID) {
425 return cond;
426 }
427 if (roaming) {
428 cond = SPN_CONDITION_DISPLAY_PLMN;
429 if ((static_cast<unsigned int>(displayConditionCust_) & static_cast<unsigned int>(SPN_COND)) == 0) {
430 cond |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_SPN);
431 }
432 } else {
433 cond = SPN_CONDITION_DISPLAY_SPN;
434 if ((static_cast<unsigned int>(displayConditionCust_) & static_cast<unsigned int>(SPN_COND_PLMN)) ==
435 SPN_COND_PLMN) {
436 cond |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_PLMN);
437 }
438 }
439 return cond;
440 }
441
GetCustEons(const std::string & numeric,int32_t lac,bool roaming,bool longNameRequired)442 std::string OperatorName::GetCustEons(const std::string &numeric, int32_t lac, bool roaming, bool longNameRequired)
443 {
444 if (!enableCust_ || numeric.empty() || pnnCust_.empty() || (oplCust_.empty() && roaming)) {
445 TELEPHONY_LOGI("OperatorName::GetCustEons is empty");
446 return "";
447 }
448 int32_t pnnIndex = 1;
449 for (std::shared_ptr<OperatorPlmnInfo> opl : oplCust_) {
450 if (opl == nullptr) {
451 continue;
452 }
453 pnnIndex = -1;
454 TELEPHONY_LOGI(
455 "OperatorName::GetCustEons numeric:%{public}s, opl->plmnNumeric:%{public}s, lac:%{public}d, "
456 "opl->lacStart:%{public}d, opl->lacEnd:%{public}d, opl->pnnRecordId:%{public}d",
457 numeric.c_str(), opl->plmnNumeric.c_str(), lac, opl->lacStart, opl->lacEnd, opl->pnnRecordId);
458 if (numeric.compare(opl->plmnNumeric) == 0 &&
459 ((opl->lacStart == 0 && opl->lacEnd == 0xfffe) || (opl->lacStart <= lac && opl->lacEnd >= lac))) {
460 pnnIndex = opl->pnnRecordId;
461 break;
462 }
463 }
464 TELEPHONY_LOGI("OperatorName::GetCustEons pnnIndex:%{public}d", pnnIndex);
465 std::string custEonsName = "";
466 if (pnnIndex >= 1 && pnnIndex <= (int32_t)pnnCust_.size()) {
467 TELEPHONY_LOGI(
468 "OperatorName::GetCustEons longNameRequired:%{public}d, longName:%{public}s, shortName:%{public}s,",
469 longNameRequired, pnnCust_.at(pnnIndex - 1)->longName.c_str(),
470 pnnCust_.at(pnnIndex - 1)->shortName.c_str());
471 if (longNameRequired) {
472 custEonsName = pnnCust_.at(pnnIndex - 1)->longName;
473 } else {
474 custEonsName = pnnCust_.at(pnnIndex - 1)->shortName;
475 }
476 }
477 return custEonsName;
478 }
479
GetCustomName(const std::string & numeric)480 std::string OperatorName::GetCustomName(const std::string &numeric)
481 {
482 return OperatorNameUtils::GetInstance().GetCustomName(numeric);
483 }
484
isDomesticRoaming(const std::string & simPlmn,const std::string & netPlmn)485 bool OperatorName::isDomesticRoaming(const std::string &simPlmn, const std::string &netPlmn)
486 {
487 if (isCMCard(simPlmn) && isCMDomestic(netPlmn)) {
488 return true;
489 }
490 if (isCUCard(simPlmn) && isCUDomestic(netPlmn)) {
491 return true;
492 }
493 if (isCTCard(simPlmn) && isCTDomestic(netPlmn)) {
494 return true;
495 }
496 if (isCBCard(simPlmn) && isCBDomestic(netPlmn)) {
497 return true;
498 }
499 TELEPHONY_LOGD("simPlmn not match netPlmn");
500 return false;
501 }
502
isCMCard(const std::string & numeric)503 bool OperatorName::isCMCard(const std::string &numeric)
504 {
505 if (numeric.empty()) {
506 return false;
507 }
508 auto obj = std::find(cmMccMnc_.begin(), cmMccMnc_.end(), numeric);
509 if (obj != cmMccMnc_.end()) {
510 TELEPHONY_LOGD("is CM card");
511 return true;
512 }
513 return false;
514 }
515
isCUCard(const std::string & numeric)516 bool OperatorName::isCUCard(const std::string &numeric)
517 {
518 if (numeric.empty()) {
519 return false;
520 }
521 auto obj = std::find(cuMccMnc_.begin(), cuMccMnc_.end(), numeric);
522 if (obj != cuMccMnc_.end()) {
523 TELEPHONY_LOGD("is CU card");
524 return true;
525 }
526 return false;
527 }
528
isCTCard(const std::string & numeric)529 bool OperatorName::isCTCard(const std::string &numeric)
530 {
531 if (numeric.empty()) {
532 return false;
533 }
534 auto obj = std::find(ctMccMnc_.begin(), ctMccMnc_.end(), numeric);
535 if (obj != ctMccMnc_.end()) {
536 TELEPHONY_LOGD("is CT card");
537 return true;
538 }
539 return false;
540 }
541
isCBCard(const std::string & numeric)542 bool OperatorName::isCBCard(const std::string &numeric)
543 {
544 if (numeric.empty()) {
545 return false;
546 }
547 auto obj = std::find(cbnMccMnc_.begin(), cbnMccMnc_.end(), numeric);
548 if (obj != cbnMccMnc_.end()) {
549 TELEPHONY_LOGD("is CB card");
550 return true;
551 }
552 return false;
553 }
554
isCMDomestic(const std::string & numeric)555 bool OperatorName::isCMDomestic(const std::string &numeric)
556 {
557 if (numeric.empty()) {
558 return false;
559 }
560 auto obj = std::find(cmDomesticMccMnc_.begin(), cmDomesticMccMnc_.end(), numeric);
561 if (obj != cmDomesticMccMnc_.end()) {
562 TELEPHONY_LOGD("is CM domestic");
563 return true;
564 }
565 return false;
566 }
567
isCUDomestic(const std::string & numeric)568 bool OperatorName::isCUDomestic(const std::string &numeric)
569 {
570 if (numeric.empty()) {
571 return false;
572 }
573 auto obj = std::find(cuDomesticMccMnc_.begin(), cuDomesticMccMnc_.end(), numeric);
574 if (obj != cuDomesticMccMnc_.end()) {
575 TELEPHONY_LOGD("is CU domestic");
576 return true;
577 }
578 return false;
579 }
580
isCTDomestic(const std::string & numeric)581 bool OperatorName::isCTDomestic(const std::string &numeric)
582 {
583 if (numeric.empty()) {
584 return false;
585 }
586 auto obj = std::find(ctDomesticMccMnc_.begin(), ctDomesticMccMnc_.end(), numeric);
587 if (obj != ctDomesticMccMnc_.end()) {
588 TELEPHONY_LOGD("is CT domestic");
589 return true;
590 }
591 return false;
592 }
593
isCBDomestic(const std::string & numeric)594 bool OperatorName::isCBDomestic(const std::string &numeric)
595 {
596 if (numeric.empty()) {
597 return false;
598 }
599 auto obj = std::find(cbDomesticnMccMnc_.begin(), cbDomesticnMccMnc_.end(), numeric);
600 if (obj != cbDomesticnMccMnc_.end()) {
601 TELEPHONY_LOGD("is CB domestic");
602 return true;
603 }
604 return false;
605 }
606
GetCurrentLac()607 int32_t OperatorName::GetCurrentLac()
608 {
609 auto networkSearchManager = networkSearchManager_.lock();
610 if (networkSearchManager == nullptr) {
611 TELEPHONY_LOGE("OperatorName::GetCurrentLac networkSearchManager is nullptr slotId:%{public}d", slotId_);
612 return 0;
613 }
614 sptr<CellLocation> location = networkSearchManager->GetCellLocation(slotId_);
615 if (location == nullptr) {
616 TELEPHONY_LOGE("OperatorName::GetCurrentLac location is nullptr slotId:%{public}d", slotId_);
617 return 0;
618 }
619 if (location->GetCellLocationType() != CellLocation::CellType::CELL_TYPE_GSM) {
620 TELEPHONY_LOGE("OperatorName::GetCurrentLac location type isn't GSM slotId:%{public}d", slotId_);
621 return 0;
622 }
623 sptr<GsmCellLocation> gsmLocation = sptr<GsmCellLocation>(static_cast<GsmCellLocation *>(location.GetRefPtr()));
624 if (gsmLocation == nullptr) {
625 TELEPHONY_LOGE("OperatorName::GetCurrentLac gsmLocation is nullptr slotId:%{public}d", slotId_);
626 return 0;
627 }
628 return gsmLocation->GetLac();
629 }
630
UpdateOperatorConfig()631 void OperatorName::UpdateOperatorConfig()
632 {
633 OperatorConfig operatorConfig;
634 CoreManagerInner::GetInstance().GetOperatorConfigs(slotId_, operatorConfig);
635 if (operatorConfig.boolValue.find(KEY_ENABLE_OPERATOR_NAME_CUST_BOOL) != operatorConfig.boolValue.end()) {
636 enableCust_ = operatorConfig.boolValue[KEY_ENABLE_OPERATOR_NAME_CUST_BOOL];
637 }
638 if (operatorConfig.stringValue.find(KEY_OPERATOR_NAME_CUST_STRING) != operatorConfig.stringValue.end()) {
639 spnCust_ = operatorConfig.stringValue[KEY_OPERATOR_NAME_CUST_STRING];
640 }
641 if (operatorConfig.intValue.find(KEY_SPN_DISPLAY_CONDITION_CUST_INT) != operatorConfig.intValue.end()) {
642 displayConditionCust_ = operatorConfig.intValue[KEY_SPN_DISPLAY_CONDITION_CUST_INT];
643 }
644 if (operatorConfig.stringArrayValue.find(KEY_PNN_CUST_STRING_ARRAY) != operatorConfig.stringArrayValue.end()) {
645 UpdatePnnCust(operatorConfig.stringArrayValue[KEY_PNN_CUST_STRING_ARRAY]);
646 }
647 if (operatorConfig.stringArrayValue.find(KEY_OPL_CUST_STRING_ARRAY) != operatorConfig.stringArrayValue.end()) {
648 UpdateOplCust(operatorConfig.stringArrayValue[KEY_OPL_CUST_STRING_ARRAY]);
649 }
650 }
651
UpdatePnnCust(const std::vector<std::string> & pnnCust)652 void OperatorName::UpdatePnnCust(const std::vector<std::string> &pnnCust)
653 {
654 pnnCust_.clear();
655 if (pnnCust.empty()) {
656 TELEPHONY_LOGE("OperatorName::UpdatePnnCust pnnCust is empty slotId:%{public}d", slotId_);
657 return;
658 }
659 for (const auto &data : pnnCust) {
660 TELEPHONY_LOGI("OperatorName::UpdatePnnCust: %{public}s", data.c_str());
661 std::vector<std::string> pnnString = NetworkUtils::SplitString(data, ",");
662 if (pnnString.size() != PNN_CUST_STRING_SIZE) {
663 continue;
664 }
665 std::shared_ptr<PlmnNetworkName> pnn = std::make_shared<PlmnNetworkName>();
666 pnn->shortName = pnnString.back();
667 pnnString.pop_back();
668 pnn->longName = pnnString.back();
669 if (!pnn->longName.empty() || !pnn->shortName.empty()) {
670 pnnCust_.push_back(pnn);
671 }
672 }
673 }
674
UpdateOplCust(const std::vector<std::string> & oplCust)675 void OperatorName::UpdateOplCust(const std::vector<std::string> &oplCust)
676 {
677 oplCust_.clear();
678 if (oplCust.empty()) {
679 TELEPHONY_LOGE("OperatorName::UpdateOplCust oplCust is empty slotId:%{public}d", slotId_);
680 return;
681 }
682 for (const auto &data : oplCust) {
683 TELEPHONY_LOGI("OperatorName::UpdateOplCust: %{public}s", data.c_str());
684 std::vector<std::string> oplString = NetworkUtils::SplitString(data, ",");
685 if (oplString.size() != OPL_CUST_STRING_SIZE || oplString.back().empty()) {
686 continue;
687 }
688 std::shared_ptr<OperatorPlmnInfo> opl = std::make_shared<OperatorPlmnInfo>();
689 int32_t base = 16; // convert to hexadecimal
690 opl->pnnRecordId = stoi(oplString.back(), 0, base);
691 oplString.pop_back();
692 if (oplString.back().empty()) {
693 continue;
694 }
695 opl->lacEnd = stoi(oplString.back(), 0, base);
696 oplString.pop_back();
697 if (oplString.back().empty()) {
698 continue;
699 }
700 opl->lacStart = stoi(oplString.back(), 0, base);
701 oplString.pop_back();
702 opl->plmnNumeric = oplString.back();
703 if (!opl->plmnNumeric.empty()) {
704 oplCust_.push_back(opl);
705 }
706 }
707 }
708
UpdateOperatorLongName(std::string & operatorLongName,const std::string & numeric)709 void OperatorName::UpdateOperatorLongName(std::string &operatorLongName, const std::string &numeric)
710 {
711 RegServiceState regStatus = RegServiceState::REG_STATE_UNKNOWN;
712 sptr<NetworkState> networkState = GetNetworkStatus();
713 if (networkState == nullptr) {
714 return;
715 }
716
717 regStatus = networkState->GetRegStatus();
718 if (regStatus != RegServiceState::REG_STATE_IN_SERVICE) {
719 return;
720 }
721
722 std::string customizedOperatorLongName = GetCustomName(numeric);
723 if (!customizedOperatorLongName.empty()) {
724 operatorLongName = customizedOperatorLongName;
725 }
726 }
727
TrySetLongOperatorNameWithTranslation()728 void OperatorName::TrySetLongOperatorNameWithTranslation()
729 {
730 sptr<NetworkState> networkState = GetNetworkStatus();
731 if (networkState != nullptr && networkSearchState_ != nullptr) {
732 std::string longOperatorName = networkState->GetLongOperatorName();
733 std::string numeric = networkState->GetPlmnNumeric();
734 UpdateOperatorLongName(longOperatorName, numeric);
735 networkSearchState_->SetLongOperatorName(longOperatorName, DomainType::DOMAIN_TYPE_CS);
736 networkSearchState_->SetLongOperatorName(longOperatorName, DomainType::DOMAIN_TYPE_PS);
737 }
738 NotifySpnChanged();
739 }
740 } // namespace Telephony
741 } // namespace OHOS
742