• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "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 "resource_utils.h"
27 #include "telephony_log_wrapper.h"
28 using namespace OHOS::AppExecFwk;
29 using namespace OHOS::EventFwk;
30 
31 namespace OHOS {
32 namespace Telephony {
33 namespace {
34 const int32_t FORMAT_IDX_SPN_CS = 0;
35 const int32_t PNN_CUST_STRING_SIZE = 2;
36 const int32_t OPL_CUST_STRING_SIZE = 4;
37 } // namespace
38 
OperatorName(const EventFwk::CommonEventSubscribeInfo & sp,std::shared_ptr<NetworkSearchState> networkSearchState,std::shared_ptr<ISimManager> simManager,std::weak_ptr<NetworkSearchManager> networkSearchManager,int32_t slotId)39 OperatorName::OperatorName(const EventFwk::CommonEventSubscribeInfo &sp,
40     std::shared_ptr<NetworkSearchState> networkSearchState, std::shared_ptr<ISimManager> simManager,
41     std::weak_ptr<NetworkSearchManager> networkSearchManager, int32_t slotId)
42     : CommonEventSubscriber(sp), networkSearchState_(networkSearchState), simManager_(simManager),
43       networkSearchManager_(networkSearchManager), slotId_(slotId)
44 {
45     std::vector<std::string> vecSpnFormats;
46     ResourceUtils::Get().GetStringArrayValueByName(ResourceUtils::SPN_FORMATS, vecSpnFormats);
47     if (vecSpnFormats.size() > FORMAT_IDX_SPN_CS) {
48         csSpnFormat_ = vecSpnFormats[FORMAT_IDX_SPN_CS];
49     }
50     UpdateOperatorConfig();
51 }
52 
OnReceiveEvent(const EventFwk::CommonEventData & data)53 void OperatorName::OnReceiveEvent(const EventFwk::CommonEventData &data)
54 {
55     const AAFwk::Want &want = data.GetWant();
56     std::string action = want.GetAction();
57     if (action == CommonEventSupport::COMMON_EVENT_OPERATOR_CONFIG_CHANGED) {
58         int32_t slotId = want.GetIntParam("slotId", 0);
59         if (slotId_ != slotId) {
60             return;
61         }
62         UpdateOperatorConfig();
63         sptr<NetworkState> networkState = GetNetworkStatus();
64         if (networkState != nullptr && networkState->GetRegStatus() == RegServiceState::REG_STATE_IN_SERVICE) {
65             NotifySpnChanged();
66         }
67     } else {
68         TELEPHONY_LOGI("OperatorName::OnReceiveEvent Slot%{public}d: action=%{public}s code=%{public}d", slotId_,
69             action.c_str(), data.GetCode());
70     }
71 }
72 
HandleOperatorInfo(const AppExecFwk::InnerEvent::Pointer & event)73 void OperatorName::HandleOperatorInfo(const AppExecFwk::InnerEvent::Pointer &event)
74 {
75     auto networkSearchManager = networkSearchManager_.lock();
76     if (networkSearchManager == nullptr) {
77         TELEPHONY_LOGE("OperatorName::HandleOperatorInfo networkSearchManager is nullptr slotId:%{public}d", slotId_);
78         return;
79     }
80     PhoneType type = networkSearchManager->GetPhoneType(slotId_);
81     if (type == PhoneType::PHONE_TYPE_IS_GSM) {
82         GsmOperatorInfo(event);
83     } else if (type == PhoneType::PHONE_TYPE_IS_CDMA) {
84         CdmaOperatorInfo(event);
85     } else {
86         TELEPHONY_LOGE("OperatorName::HandleOperatorInfo phone type:%{public}d invalid", type);
87     }
88     networkSearchManager->decMsgNum(slotId_);
89     if (networkSearchManager->CheckIsNeedNotify(slotId_)) {
90         networkSearchManager->ProcessNotifyStateChangeEvent(slotId_);
91     }
92 
93     NotifySpnChanged();
94     networkSearchManager->TriggerTimezoneRefresh(slotId_);
95 }
96 
GsmOperatorInfo(const AppExecFwk::InnerEvent::Pointer & event) const97 void OperatorName::GsmOperatorInfo(const AppExecFwk::InnerEvent::Pointer &event) const
98 {
99     if (event == nullptr) {
100         TELEPHONY_LOGE("OperatorName::GsmOperatorInfo event is nullptr slotId:%{public}d", slotId_);
101         return;
102     }
103     std::string longName = "";
104     std::string shortName = "";
105     std::string numeric = "";
106     std::shared_ptr<OperatorInfoResult> operatorInfoResult = event->GetSharedObject<OperatorInfoResult>();
107     if (operatorInfoResult != nullptr) {
108         longName = operatorInfoResult->longName;
109         shortName = operatorInfoResult->shortName;
110         numeric = operatorInfoResult->numeric;
111     }
112     TELEPHONY_LOGI(
113         "OperatorName::GsmOperatorInfo longName : %{public}s, shortName : %{public}s, numeric : %{public}s "
114         "slotId:%{public}d",
115         longName.c_str(), shortName.c_str(), numeric.c_str(), slotId_);
116     if (networkSearchState_ != nullptr) {
117         networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_CS);
118         networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_PS);
119     }
120 }
121 
CdmaOperatorInfo(const AppExecFwk::InnerEvent::Pointer & event) const122 void OperatorName::CdmaOperatorInfo(const AppExecFwk::InnerEvent::Pointer &event) const
123 {
124     if (event == nullptr) {
125         TELEPHONY_LOGE("OperatorName::CdmaOperatorInfo event is nullptr slotId:%{public}d", slotId_);
126         return;
127     }
128     std::string longName = "";
129     std::string shortName = "";
130     std::string numeric = "";
131     std::shared_ptr<OperatorInfoResult> operatorInfoResult = event->GetSharedObject<OperatorInfoResult>();
132     if (operatorInfoResult != nullptr) {
133         longName = operatorInfoResult->longName;
134         shortName = operatorInfoResult->shortName;
135         numeric = operatorInfoResult->numeric;
136     }
137     TELEPHONY_LOGI(
138         "OperatorName::CdmaOperatorInfo longName : %{public}s, shortName : %{public}s, numeric : %{public}s "
139         "slotId:%{public}d",
140         longName.c_str(), shortName.c_str(), numeric.c_str(), slotId_);
141     if (networkSearchState_ != nullptr) {
142         networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_CS);
143         networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_PS);
144     }
145 }
146 
GetNetworkStatus()147 sptr<NetworkState> OperatorName::GetNetworkStatus()
148 {
149     if (networkSearchState_ != nullptr) {
150         std::unique_ptr<NetworkState> networkState = networkSearchState_->GetNetworkStatus();
151         if (networkState != nullptr) {
152             networkState_ = networkState.release();
153             return networkState_;
154         }
155     }
156     TELEPHONY_LOGE("OperatorName::GetNetworkStatus networkState is nullptr slotId:%{public}d", slotId_);
157     networkState_ = nullptr;
158     return networkState_;
159 }
160 
161 /**
162  * 3GPP TS 51.011 V5.0.0(2001-12) 10.3.11
163  */
NotifySpnChanged()164 void OperatorName::NotifySpnChanged()
165 {
166     auto networkSearchManager = networkSearchManager_.lock();
167     if (networkSearchManager == nullptr) {
168         TELEPHONY_LOGE("OperatorName::NotifySpnChanged networkSearchManager is nullptr slotId:%{public}d", slotId_);
169         return;
170     }
171     TELEPHONY_LOGI("OperatorName::NotifySpnChanged slotId:%{public}d", slotId_);
172     RegServiceState regStatus = RegServiceState::REG_STATE_UNKNOWN;
173     sptr<NetworkState> networkState = GetNetworkStatus();
174     if (networkState != nullptr) {
175         regStatus = networkState->GetRegStatus();
176     } else {
177         TELEPHONY_LOGE("OperatorName::NotifySpnChanged networkState is nullptr slotId:%{public}d", slotId_);
178     }
179     if (networkSearchManager->GetPhoneType(slotId_) == PhoneType::PHONE_TYPE_IS_GSM) {
180         NotifyGsmSpnChanged(regStatus, networkState);
181     } else if (networkSearchManager->GetPhoneType(slotId_) == PhoneType::PHONE_TYPE_IS_CDMA) {
182         NotifyCdmaSpnChanged(regStatus, networkState);
183     }
184 }
185 
UpdatePlmn(RegServiceState regStatus,sptr<NetworkState> & networkState,int32_t spnRule,std::string & plmn,bool & showPlmn)186 void OperatorName::UpdatePlmn(
187     RegServiceState regStatus, sptr<NetworkState> &networkState, int32_t spnRule, std::string &plmn, bool &showPlmn)
188 {
189     if (networkState != nullptr) {
190         switch (regStatus) {
191             case RegServiceState::REG_STATE_IN_SERVICE:
192                 plmn = GetPlmn(networkState, true);
193                 showPlmn =
194                     !plmn.empty() && ((static_cast<uint32_t>(spnRule) & SpnShowType::SPN_CONDITION_DISPLAY_PLMN) ==
195                                          SpnShowType::SPN_CONDITION_DISPLAY_PLMN);
196                 break;
197             case RegServiceState::REG_STATE_NO_SERVICE:
198             case RegServiceState::REG_STATE_EMERGENCY_ONLY:
199             case RegServiceState::REG_STATE_SEARCH:
200                 if (networkState->IsEmergency()) {
201                     ResourceUtils::Get().GetStringValueByName(ResourceUtils::EMERGENCY_CALLS_ONLY, plmn);
202                 } else {
203                     ResourceUtils::Get().GetStringValueByName(ResourceUtils::OUT_OF_SERIVCE, plmn);
204                 }
205                 showPlmn = true;
206                 break;
207             case RegServiceState::REG_STATE_UNKNOWN:
208             case RegServiceState::REG_STATE_POWER_OFF:
209             default:
210                 ResourceUtils::Get().GetStringValueByName(ResourceUtils::OUT_OF_SERIVCE, plmn);
211                 showPlmn = true;
212                 break;
213         }
214     }
215 }
216 
UpdateSpn(RegServiceState regStatus,sptr<NetworkState> & networkState,int32_t spnRule,std::string & spn,bool & showSpn)217 void OperatorName::UpdateSpn(
218     RegServiceState regStatus, sptr<NetworkState> &networkState, int32_t spnRule, std::string &spn, bool &showSpn)
219 {
220     if (regStatus == RegServiceState::REG_STATE_IN_SERVICE) {
221         if (enableCust_ && !spnCust_.empty()) {
222             spn = spnCust_;
223         }
224         if (spn.empty()) {
225             std::u16string result = Str8ToStr16("");
226             if (simManager_ != nullptr) {
227                 simManager_->GetSimSpn(slotId_, result);
228             }
229             spn = Str16ToStr8(result);
230         }
231         if (!csSpnFormat_.empty()) {
232             spn = NetworkUtils::FormatString(csSpnFormat_, spn.c_str());
233         }
234         showSpn = !spn.empty() && ((static_cast<uint32_t>(spnRule) & SpnShowType::SPN_CONDITION_DISPLAY_SPN) ==
235                                       SpnShowType::SPN_CONDITION_DISPLAY_SPN);
236     } else {
237         spn = "";
238         showSpn = false;
239     }
240 }
241 
NotifyGsmSpnChanged(RegServiceState regStatus,sptr<NetworkState> & networkState)242 void OperatorName::NotifyGsmSpnChanged(RegServiceState regStatus, sptr<NetworkState> &networkState)
243 {
244     if (networkState == nullptr) {
245         TELEPHONY_LOGE("OperatorName::NotifyGsmSpnChanged networkState is nullptr slotId:%{public}d", slotId_);
246         return;
247     }
248     int32_t spnRule = 0;
249     std::string plmn = "";
250     std::string spn = "";
251     bool showPlmn = false;
252     bool showSpn = false;
253     bool roaming = networkState->IsRoaming();
254     if (enableCust_ && displayConditionCust_ != SPN_INVALID) {
255         spnRule = GetCustSpnRule(roaming);
256     } else {
257         std::string numeric = networkState->GetPlmnNumeric();
258         if (simManager_ != nullptr) {
259             spnRule = simManager_->ObtainSpnCondition(slotId_, roaming, numeric);
260         }
261     }
262     UpdatePlmn(regStatus, networkState, spnRule, plmn, showPlmn);
263     UpdateSpn(regStatus, networkState, spnRule, spn, showSpn);
264     TELEPHONY_LOGI(
265         "OperatorName::NotifyGsmSpnChanged showSpn:%{public}d curSpn_:%{public}s spn:%{public}s showPlmn:%{public}d "
266         "curPlmn_:%{public}s plmn:%{public}s slotId:%{public}d",
267         showSpn, curSpn_.c_str(), spn.c_str(), showPlmn, curPlmn_.c_str(), plmn.c_str(), slotId_);
268     if (curSpnRule_ != spnRule || curRegState_ != regStatus || curSpnShow_ != showSpn || curPlmnShow_ != showPlmn ||
269         curSpn_.compare(spn) || curPlmn_.compare(plmn)) {
270         TELEPHONY_LOGI("OperatorName::NotifyGsmSpnChanged start send broadcast slotId:%{public}d...", slotId_);
271         PublishEvent(spnRule, regStatus, showPlmn, plmn, showSpn, spn);
272     } else {
273         TELEPHONY_LOGI(
274             "OperatorName::NotifyGsmSpnChanged spn no changed, not need to update slotId:%{public}d", slotId_);
275     }
276 }
277 
NotifyCdmaSpnChanged(RegServiceState regStatus,sptr<NetworkState> & networkState)278 void OperatorName::NotifyCdmaSpnChanged(RegServiceState regStatus, sptr<NetworkState> &networkState)
279 {
280     if (networkState == nullptr) {
281         TELEPHONY_LOGE("OperatorName::NotifyCdmaSpnChanged networkState is nullptr slotId:%{public}d", slotId_);
282         return;
283     }
284     int32_t spnRule = 0;
285     std::string plmn = "";
286     std::string spn = "";
287     bool showPlmn = false;
288     bool showSpn = false;
289     std::string numeric = networkState->GetPlmnNumeric();
290     if (regStatus == RegServiceState::REG_STATE_IN_SERVICE) {
291         plmn = GetCustomName(numeric);
292         if (plmn.empty()) {
293             plmn = networkState->GetLongOperatorName();
294         }
295         if (!csSpnFormat_.empty()) {
296             plmn = NetworkUtils::FormatString(csSpnFormat_, plmn.c_str());
297         }
298     } else if (regStatus != RegServiceState::REG_STATE_POWER_OFF) {
299         ResourceUtils::Get().GetStringValueByName(ResourceUtils::OUT_OF_SERIVCE, plmn);
300     }
301     showPlmn = !plmn.empty();
302     TELEPHONY_LOGI(
303         "OperatorName::NotifyCdmaSpnChanged showSpn:%{public}d curSpn_:%{public}s spn:%{public}s "
304         "showPlmn:%{public}d curPlmn_:%{public}s plmn:%{public}s slotId:%{public}d",
305         showSpn, curSpn_.c_str(), spn.c_str(), showPlmn, curPlmn_.c_str(), plmn.c_str(), slotId_);
306     if (curSpnRule_ != spnRule || curRegState_ != regStatus || curSpnShow_ != showSpn || curPlmnShow_ != showPlmn ||
307         curSpn_.compare(spn) || curPlmn_.compare(plmn)) {
308         TELEPHONY_LOGI("OperatorName::NotifyCdmaSpnChanged start send broadcast slotId:%{public}d...", slotId_);
309         PublishEvent(spnRule, regStatus, showPlmn, plmn, showSpn, spn);
310     } else {
311         TELEPHONY_LOGI(
312             "OperatorName::NotifyCdmaSpnChanged spn no changed, not need to update slotId:%{public}d", slotId_);
313     }
314 }
315 
PublishEvent(const int32_t rule,const RegServiceState state,const bool showPlmn,const std::string & plmn,const bool showSpn,const std::string & spn)316 void OperatorName::PublishEvent(const int32_t rule, const RegServiceState state, const bool showPlmn,
317     const std::string &plmn, const bool showSpn, const std::string &spn)
318 {
319     Want want;
320     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SPN_INFO_CHANGED);
321     want.SetParam(CUR_SLOT_ID, slotId_);
322     want.SetParam(CUR_PLMN_SHOW, showPlmn);
323     want.SetParam(CUR_PLMN, plmn);
324     want.SetParam(CUR_SPN_SHOW, showSpn);
325     want.SetParam(CUR_SPN, spn);
326     CommonEventData data;
327     data.SetWant(want);
328 
329     CommonEventPublishInfo publishInfo;
330     publishInfo.SetSticky(true);
331     bool publishResult = CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
332     TELEPHONY_LOGI("OperatorName::PublishEvent result : %{public}d slotId:%{public}d", publishResult, slotId_);
333     if (publishResult) {
334         curRegState_ = state;
335         curSpnRule_ = rule;
336         curSpn_ = spn;
337         curSpnShow_ = showSpn;
338         curPlmn_ = plmn;
339         curPlmnShow_ = showPlmn;
340     }
341 }
342 
GetPlmn(const sptr<NetworkState> & networkState,bool longNameRequired)343 std::string OperatorName::GetPlmn(const sptr<NetworkState> &networkState, bool longNameRequired)
344 {
345     if (networkState == nullptr) {
346         TELEPHONY_LOGE("OperatorName::GetPlmn networkState is nullptr slotId:%{public}d", slotId_);
347         return "";
348     }
349     std::string plmn = "";
350     std::string numeric = networkState->GetPlmnNumeric();
351     bool roaming = networkState->IsRoaming();
352     int32_t lac = GetCurrentLac();
353     plmn = GetCustomName(numeric);
354     if (plmn.empty()) {
355         plmn = GetCustEons(numeric, lac, roaming, longNameRequired);
356     }
357     if (plmn.empty()) {
358         plmn = GetEons(numeric, lac, longNameRequired);
359     }
360     if (plmn.empty()) {
361         plmn = networkState->GetLongOperatorName();
362     }
363     TELEPHONY_LOGD(
364         "OperatorName::GetPlmn lac:%{public}d, numeric:%{public}s, longNameRequired:%{public}d, plmn:%{public}s", lac,
365         numeric.c_str(), longNameRequired, plmn.c_str());
366     return plmn;
367 }
368 
GetEons(const std::string & numeric,int32_t lac,bool longNameRequired)369 std::string OperatorName::GetEons(const std::string &numeric, int32_t lac, bool longNameRequired)
370 {
371     if (simManager_ == nullptr) {
372         TELEPHONY_LOGE("OperatorName::GetEons simManager_ is nullptr slotId:%{public}d", slotId_);
373         return "";
374     }
375     return Str16ToStr8(simManager_->GetSimEons(slotId_, numeric, lac, longNameRequired));
376 }
377 
GetCustSpnRule(bool roaming)378 unsigned int OperatorName::GetCustSpnRule(bool roaming)
379 {
380     unsigned int cond = 0;
381     if (displayConditionCust_ <= SPN_INVALID) {
382         return cond;
383     }
384     if (roaming) {
385         cond = SPN_CONDITION_DISPLAY_PLMN;
386         if ((static_cast<unsigned int>(displayConditionCust_) & static_cast<unsigned int>(SPN_COND)) == 0) {
387             cond |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_SPN);
388         }
389     } else {
390         cond = SPN_CONDITION_DISPLAY_SPN;
391         if ((static_cast<unsigned int>(displayConditionCust_) & static_cast<unsigned int>(SPN_COND_PLMN)) ==
392             SPN_COND_PLMN) {
393             cond |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_PLMN);
394         }
395     }
396     return cond;
397 }
398 
GetCustEons(const std::string & numeric,int32_t lac,bool roaming,bool longNameRequired)399 std::string OperatorName::GetCustEons(const std::string &numeric, int32_t lac, bool roaming, bool longNameRequired)
400 {
401     if (!enableCust_ || numeric.empty() || pnnCust_.empty() || (oplCust_.empty() && roaming)) {
402         TELEPHONY_LOGI("OperatorName::GetCustEons is empty");
403         return "";
404     }
405     int32_t pnnIndex = 1;
406     for (std::shared_ptr<OperatorPlmnInfo> opl : oplCust_) {
407         if (opl == nullptr) {
408             continue;
409         }
410         pnnIndex = -1;
411         TELEPHONY_LOGI(
412             "OperatorName::GetCustEons numeric:%{public}s, opl->plmnNumeric:%{public}s, lac:%{public}d, "
413             "opl->lacStart:%{public}d, opl->lacEnd:%{public}d, opl->pnnRecordId:%{public}d",
414             numeric.c_str(), opl->plmnNumeric.c_str(), lac, opl->lacStart, opl->lacEnd, opl->pnnRecordId);
415         if (numeric.compare(opl->plmnNumeric) == 0 &&
416             ((opl->lacStart == 0 && opl->lacEnd == 0xfffe) || (opl->lacStart <= lac && opl->lacEnd >= lac))) {
417             pnnIndex = opl->pnnRecordId;
418             break;
419         }
420     }
421     TELEPHONY_LOGI("OperatorName::GetCustEons pnnIndex:%{public}d", pnnIndex);
422     std::string custEonsName = "";
423     if (pnnIndex >= 1 && pnnIndex <= (int32_t)pnnCust_.size()) {
424         TELEPHONY_LOGI(
425             "OperatorName::GetCustEons longNameRequired:%{public}d, longName:%{public}s, shortName:%{public}s,",
426             longNameRequired, pnnCust_.at(pnnIndex - 1)->longName.c_str(),
427             pnnCust_.at(pnnIndex - 1)->shortName.c_str());
428         if (longNameRequired) {
429             custEonsName = pnnCust_.at(pnnIndex - 1)->longName;
430         } else {
431             custEonsName = pnnCust_.at(pnnIndex - 1)->shortName;
432         }
433     }
434     return custEonsName;
435 }
436 
GetCustomName(const std::string & numeric)437 std::string OperatorName::GetCustomName(const std::string &numeric)
438 {
439     TELEPHONY_LOGD("OperatorName::GetCustomName numeric:%{public}s", numeric.c_str());
440     std::string name = "";
441     if (numeric.empty()) {
442         return name;
443     }
444     auto obj = std::find(cmMccMnc_.begin(), cmMccMnc_.end(), numeric);
445     if (obj != cmMccMnc_.end()) {
446         ResourceUtils::Get().GetStringValueByName(ResourceUtils::CMCC, name);
447         TELEPHONY_LOGD("OperatorName::GetCustomName CMCC:%{public}s", name.c_str());
448         return name;
449     }
450     obj = std::find(cuMccMnc_.begin(), cuMccMnc_.end(), numeric);
451     if (obj != cuMccMnc_.end()) {
452         ResourceUtils::Get().GetStringValueByName(ResourceUtils::CUCC, name);
453         TELEPHONY_LOGD("OperatorName::GetCustomName CUCC:%{public}s", name.c_str());
454         return name;
455     }
456     obj = std::find(ctMccMnc_.begin(), ctMccMnc_.end(), numeric);
457     if (obj != ctMccMnc_.end()) {
458         ResourceUtils::Get().GetStringValueByName(ResourceUtils::CTCC, name);
459         TELEPHONY_LOGD("OperatorName::GetCustomName CTCC:%{public}s", name.c_str());
460         return name;
461     }
462     return name;
463 }
464 
GetCurrentLac()465 int32_t OperatorName::GetCurrentLac()
466 {
467     auto networkSearchManager = networkSearchManager_.lock();
468     if (networkSearchManager == nullptr) {
469         TELEPHONY_LOGE("OperatorName::GetCurrentLac networkSearchManager is nullptr slotId:%{public}d", slotId_);
470         return 0;
471     }
472     sptr<CellLocation> location = networkSearchManager->GetCellLocation(slotId_);
473     if (location == nullptr) {
474         TELEPHONY_LOGE("OperatorName::GetCurrentLac location is nullptr slotId:%{public}d", slotId_);
475         return 0;
476     }
477     if (location->GetCellLocationType() != CellLocation::CellType::CELL_TYPE_GSM) {
478         TELEPHONY_LOGE("OperatorName::GetCurrentLac location type isn't GSM slotId:%{public}d", slotId_);
479         return 0;
480     }
481     sptr<GsmCellLocation> gsmLocation = sptr<GsmCellLocation>(static_cast<GsmCellLocation *>(location.GetRefPtr()));
482     if (gsmLocation == nullptr) {
483         TELEPHONY_LOGE("OperatorName::GetCurrentLac gsmLocation is nullptr slotId:%{public}d", slotId_);
484         return 0;
485     }
486     return gsmLocation->GetLac();
487 }
488 
UpdateOperatorConfig()489 void OperatorName::UpdateOperatorConfig()
490 {
491     OperatorConfig operatorConfig;
492     CoreManagerInner::GetInstance().GetOperatorConfigs(slotId_, operatorConfig);
493     if (operatorConfig.boolValue.find(KEY_ENABLE_OPERATOR_NAME_CUST_BOOL) != operatorConfig.boolValue.end()) {
494         enableCust_ = operatorConfig.boolValue[KEY_ENABLE_OPERATOR_NAME_CUST_BOOL];
495     }
496     if (operatorConfig.stringValue.find(KEY_OPERATOR_NAME_CUST_STRING) != operatorConfig.stringValue.end()) {
497         spnCust_ = operatorConfig.stringValue[KEY_OPERATOR_NAME_CUST_STRING];
498     }
499     if (operatorConfig.intValue.find(KEY_SPN_DISPLAY_CONDITION_CUST_INT) != operatorConfig.intValue.end()) {
500         displayConditionCust_ = operatorConfig.intValue[KEY_SPN_DISPLAY_CONDITION_CUST_INT];
501     }
502     if (operatorConfig.stringArrayValue.find(KEY_PNN_CUST_STRING_ARRAY) != operatorConfig.stringArrayValue.end()) {
503         UpdatePnnCust(operatorConfig.stringArrayValue[KEY_PNN_CUST_STRING_ARRAY]);
504     }
505     if (operatorConfig.stringArrayValue.find(KEY_OPL_CUST_STRING_ARRAY) != operatorConfig.stringArrayValue.end()) {
506         UpdateOplCust(operatorConfig.stringArrayValue[KEY_OPL_CUST_STRING_ARRAY]);
507     }
508 }
509 
UpdatePnnCust(const std::vector<std::string> & pnnCust)510 void OperatorName::UpdatePnnCust(const std::vector<std::string> &pnnCust)
511 {
512     pnnCust_.clear();
513     if (pnnCust.empty()) {
514         TELEPHONY_LOGE("OperatorName::UpdatePnnCust pnnCust is empty slotId:%{public}d", slotId_);
515         return;
516     }
517     for (const auto &data : pnnCust) {
518         TELEPHONY_LOGI("OperatorName::UpdatePnnCust: %{public}s", data.c_str());
519         std::vector<std::string> pnnString = NetworkUtils::SplitString(data, ",");
520         if (pnnString.size() != PNN_CUST_STRING_SIZE) {
521             continue;
522         }
523         std::shared_ptr<PlmnNetworkName> pnn = std::make_shared<PlmnNetworkName>();
524         pnn->shortName = pnnString.back();
525         pnnString.pop_back();
526         pnn->longName = pnnString.back();
527         if (!pnn->longName.empty() || !pnn->shortName.empty()) {
528             pnnCust_.push_back(pnn);
529         }
530     }
531 }
532 
UpdateOplCust(const std::vector<std::string> & oplCust)533 void OperatorName::UpdateOplCust(const std::vector<std::string> &oplCust)
534 {
535     oplCust_.clear();
536     if (oplCust.empty()) {
537         TELEPHONY_LOGE("OperatorName::UpdateOplCust oplCust is empty slotId:%{public}d", slotId_);
538         return;
539     }
540     for (const auto &data : oplCust) {
541         TELEPHONY_LOGI("OperatorName::UpdateOplCust: %{public}s", data.c_str());
542         std::vector<std::string> oplString = NetworkUtils::SplitString(data, ",");
543         if (oplString.size() != OPL_CUST_STRING_SIZE || oplString.back().empty()) {
544             continue;
545         }
546         std::shared_ptr<OperatorPlmnInfo> opl = std::make_shared<OperatorPlmnInfo>();
547         int32_t base = 16; // convert to hexadecimal
548         opl->pnnRecordId = stoi(oplString.back(), 0, base);
549         oplString.pop_back();
550         if (oplString.back().empty()) {
551             continue;
552         }
553         opl->lacEnd = stoi(oplString.back(), 0, base);
554         oplString.pop_back();
555         if (oplString.back().empty()) {
556             continue;
557         }
558         opl->lacStart = stoi(oplString.back(), 0, base);
559         oplString.pop_back();
560         opl->plmnNumeric = oplString.back();
561         if (!opl->plmnNumeric.empty()) {
562             oplCust_.push_back(opl);
563         }
564     }
565 }
566 } // namespace Telephony
567 } // namespace OHOS
568