• 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().GetValueByName<std::vector<std::string>>(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 (networkSearchState_ != nullptr) {
90         if (networkSearchManager->CheckIsNeedNotify(slotId_)) {
91             networkSearchState_->NotifyStateChange();
92         }
93     }
94 
95     NotifySpnChanged();
96     networkSearchManager->TriggerTimezoneRefresh(slotId_);
97 }
98 
GsmOperatorInfo(const AppExecFwk::InnerEvent::Pointer & event) const99 void OperatorName::GsmOperatorInfo(const AppExecFwk::InnerEvent::Pointer &event) const
100 {
101     if (event == nullptr) {
102         TELEPHONY_LOGE("OperatorName::GsmOperatorInfo event is nullptr slotId:%{public}d", slotId_);
103         return;
104     }
105     std::string longName = "";
106     std::string shortName = "";
107     std::string numeric = "";
108     std::shared_ptr<OperatorInfoResult> operatorInfoResult = event->GetSharedObject<OperatorInfoResult>();
109     if (operatorInfoResult != nullptr) {
110         longName = operatorInfoResult->longName;
111         shortName = operatorInfoResult->shortName;
112         numeric = operatorInfoResult->numeric;
113     }
114     TELEPHONY_LOGI(
115         "OperatorName::GsmOperatorInfo longName : %{public}s, shortName : %{public}s, numeric : %{public}s "
116         "slotId:%{public}d",
117         longName.c_str(), shortName.c_str(), numeric.c_str(), slotId_);
118     if (networkSearchState_ != nullptr) {
119         networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_CS);
120         networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_PS);
121     }
122 }
123 
CdmaOperatorInfo(const AppExecFwk::InnerEvent::Pointer & event) const124 void OperatorName::CdmaOperatorInfo(const AppExecFwk::InnerEvent::Pointer &event) const
125 {
126     if (event == nullptr) {
127         TELEPHONY_LOGE("OperatorName::CdmaOperatorInfo 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     }
139     TELEPHONY_LOGI(
140         "OperatorName::CdmaOperatorInfo longName : %{public}s, shortName : %{public}s, numeric : %{public}s "
141         "slotId:%{public}d",
142         longName.c_str(), shortName.c_str(), numeric.c_str(), slotId_);
143     if (networkSearchState_ != nullptr) {
144         networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_CS);
145         networkSearchState_->SetOperatorInfo(longName, shortName, numeric, DomainType::DOMAIN_TYPE_PS);
146     }
147 }
148 
GetNetworkStatus()149 sptr<NetworkState> OperatorName::GetNetworkStatus()
150 {
151     if (networkSearchState_ != nullptr) {
152         std::unique_ptr<NetworkState> networkState = networkSearchState_->GetNetworkStatus();
153         if (networkState != nullptr) {
154             networkState_ = networkState.release();
155             return networkState_;
156         }
157     }
158     TELEPHONY_LOGE("OperatorName::GetNetworkStatus networkState is nullptr slotId:%{public}d", slotId_);
159     networkState_ = nullptr;
160     return networkState_;
161 }
162 
163 /**
164  * 3GPP TS 51.011 V5.0.0(2001-12) 10.3.11
165  */
NotifySpnChanged()166 void OperatorName::NotifySpnChanged()
167 {
168     auto networkSearchManager = networkSearchManager_.lock();
169     if (networkSearchManager == nullptr) {
170         TELEPHONY_LOGE("OperatorName::NotifySpnChanged networkSearchManager is nullptr slotId:%{public}d", slotId_);
171         return;
172     }
173     TELEPHONY_LOGI("OperatorName::NotifySpnChanged slotId:%{public}d", slotId_);
174     RegServiceState regStatus = RegServiceState::REG_STATE_UNKNOWN;
175     sptr<NetworkState> networkState = GetNetworkStatus();
176     if (networkState != nullptr) {
177         regStatus = networkState->GetRegStatus();
178     } else {
179         TELEPHONY_LOGE("OperatorName::NotifySpnChanged networkState is nullptr slotId:%{public}d", slotId_);
180     }
181     if (networkSearchManager->GetPhoneType(slotId_) == PhoneType::PHONE_TYPE_IS_GSM) {
182         NotifyGsmSpnChanged(regStatus, networkState);
183     } else if (networkSearchManager->GetPhoneType(slotId_) == PhoneType::PHONE_TYPE_IS_CDMA) {
184         NotifyCdmaSpnChanged(regStatus, networkState);
185     }
186 }
187 
UpdatePlmn(RegServiceState regStatus,sptr<NetworkState> & networkState,int32_t spnRule,std::string & plmn,bool & showPlmn)188 void OperatorName::UpdatePlmn(
189     RegServiceState regStatus, sptr<NetworkState> &networkState, int32_t spnRule, std::string &plmn, bool &showPlmn)
190 {
191     if (networkState != nullptr) {
192         switch (regStatus) {
193             case RegServiceState::REG_STATE_IN_SERVICE:
194                 plmn = GetPlmn(networkState, true);
195                 showPlmn =
196                     !plmn.empty() && ((static_cast<uint32_t>(spnRule) & SpnShowType::SPN_CONDITION_DISPLAY_PLMN) ==
197                                          SpnShowType::SPN_CONDITION_DISPLAY_PLMN);
198                 break;
199             case RegServiceState::REG_STATE_NO_SERVICE:
200             case RegServiceState::REG_STATE_EMERGENCY_ONLY:
201             case RegServiceState::REG_STATE_SEARCH:
202                 if (networkState->IsEmergency()) {
203                     ResourceUtils::Get().GetValueByName<std::string>(ResourceUtils::EMERGENCY_CALLS_ONLY, plmn);
204                 } else {
205                     ResourceUtils::Get().GetValueByName<std::string>(ResourceUtils::OUT_OF_SERIVCE, plmn);
206                 }
207                 showPlmn = true;
208                 break;
209             case RegServiceState::REG_STATE_UNKNOWN:
210             case RegServiceState::REG_STATE_POWER_OFF:
211             default:
212                 ResourceUtils::Get().GetValueByName<std::string>(ResourceUtils::OUT_OF_SERIVCE, plmn);
213                 showPlmn = true;
214                 break;
215         }
216     }
217 }
218 
UpdateSpn(RegServiceState regStatus,sptr<NetworkState> & networkState,int32_t spnRule,std::string & spn,bool & showSpn)219 void OperatorName::UpdateSpn(
220     RegServiceState regStatus, sptr<NetworkState> &networkState, int32_t spnRule, std::string &spn, bool &showSpn)
221 {
222     if (regStatus == RegServiceState::REG_STATE_IN_SERVICE) {
223         if (enableCust_ && !spnCust_.empty()) {
224             spn = spnCust_;
225         }
226         if (spn.empty()) {
227             std::u16string result = Str8ToStr16("");
228             if (simManager_ != nullptr) {
229                 simManager_->GetSimSpn(slotId_, result);
230             }
231             spn = Str16ToStr8(result);
232         }
233         if (!csSpnFormat_.empty()) {
234             spn = NetworkUtils::FormatString(csSpnFormat_, spn.c_str());
235         }
236         showSpn = !spn.empty() && ((static_cast<uint32_t>(spnRule) & SpnShowType::SPN_CONDITION_DISPLAY_SPN) ==
237                                       SpnShowType::SPN_CONDITION_DISPLAY_SPN);
238     } else {
239         spn = "";
240         showSpn = false;
241     }
242 }
243 
NotifyGsmSpnChanged(RegServiceState regStatus,sptr<NetworkState> & networkState)244 void OperatorName::NotifyGsmSpnChanged(RegServiceState regStatus, sptr<NetworkState> &networkState)
245 {
246     if (networkState == nullptr) {
247         TELEPHONY_LOGE("OperatorName::NotifyGsmSpnChanged networkState is nullptr slotId:%{public}d", slotId_);
248         return;
249     }
250     int32_t spnRule = 0;
251     std::string plmn = "";
252     std::string spn = "";
253     bool showPlmn = false;
254     bool showSpn = false;
255     bool roaming = networkState->IsRoaming();
256     if (enableCust_ && displayConditionCust_ != SPN_INVALID) {
257         spnRule = GetCustSpnRule(roaming);
258     } else {
259         std::string numeric = networkState->GetPlmnNumeric();
260         if (simManager_ != nullptr) {
261             spnRule = simManager_->ObtainSpnCondition(slotId_, roaming, numeric);
262         }
263     }
264     UpdatePlmn(regStatus, networkState, spnRule, plmn, showPlmn);
265     UpdateSpn(regStatus, networkState, spnRule, spn, showSpn);
266     TELEPHONY_LOGI(
267         "OperatorName::NotifyGsmSpnChanged showSpn:%{public}d curSpn_:%{public}s spn:%{public}s showPlmn:%{public}d "
268         "curPlmn_:%{public}s plmn:%{public}s slotId:%{public}d",
269         showSpn, curSpn_.c_str(), spn.c_str(), showPlmn, curPlmn_.c_str(), plmn.c_str(), slotId_);
270     if (curSpnRule_ != spnRule || curRegState_ != regStatus || curSpnShow_ != showSpn || curPlmnShow_ != showPlmn ||
271         curSpn_.compare(spn) || curPlmn_.compare(plmn)) {
272         TELEPHONY_LOGI("OperatorName::NotifyGsmSpnChanged start send broadcast slotId:%{public}d...", slotId_);
273         PublishEvent(spnRule, regStatus, showPlmn, plmn, showSpn, spn);
274     } else {
275         TELEPHONY_LOGI(
276             "OperatorName::NotifyGsmSpnChanged spn no changed, not need to update slotId:%{public}d", slotId_);
277     }
278 }
279 
NotifyCdmaSpnChanged(RegServiceState regStatus,sptr<NetworkState> & networkState)280 void OperatorName::NotifyCdmaSpnChanged(RegServiceState regStatus, sptr<NetworkState> &networkState)
281 {
282     if (networkState == nullptr) {
283         TELEPHONY_LOGE("OperatorName::NotifyCdmaSpnChanged networkState is nullptr slotId:%{public}d", slotId_);
284         return;
285     }
286     int32_t spnRule = 0;
287     std::string plmn = "";
288     std::string spn = "";
289     bool showPlmn = false;
290     bool showSpn = false;
291     std::string numeric = networkState->GetPlmnNumeric();
292     if (regStatus == RegServiceState::REG_STATE_IN_SERVICE) {
293         plmn = GetCustomName(numeric);
294         if (plmn.empty()) {
295             plmn = networkState->GetLongOperatorName();
296         }
297         if (!csSpnFormat_.empty()) {
298             plmn = NetworkUtils::FormatString(csSpnFormat_, plmn.c_str());
299         }
300     } else if (regStatus != RegServiceState::REG_STATE_POWER_OFF) {
301         ResourceUtils::Get().GetValueByName<std::string>(ResourceUtils::OUT_OF_SERIVCE, plmn);
302     }
303     showPlmn = !plmn.empty();
304     TELEPHONY_LOGI(
305         "OperatorName::NotifyCdmaSpnChanged showSpn:%{public}d curSpn_:%{public}s spn:%{public}s "
306         "showPlmn:%{public}d curPlmn_:%{public}s plmn:%{public}s slotId:%{public}d",
307         showSpn, curSpn_.c_str(), spn.c_str(), showPlmn, curPlmn_.c_str(), plmn.c_str(), slotId_);
308     if (curSpnRule_ != spnRule || curRegState_ != regStatus || curSpnShow_ != showSpn || curPlmnShow_ != showPlmn ||
309         curSpn_.compare(spn) || curPlmn_.compare(plmn)) {
310         TELEPHONY_LOGI("OperatorName::NotifyCdmaSpnChanged start send broadcast slotId:%{public}d...", slotId_);
311         PublishEvent(spnRule, regStatus, showPlmn, plmn, showSpn, spn);
312     } else {
313         TELEPHONY_LOGI(
314             "OperatorName::NotifyCdmaSpnChanged spn no changed, not need to update slotId:%{public}d", slotId_);
315     }
316 }
317 
PublishEvent(const int32_t rule,const RegServiceState state,const bool showPlmn,const std::string & plmn,const bool showSpn,const std::string & spn)318 void OperatorName::PublishEvent(const int32_t rule, const RegServiceState state, const bool showPlmn,
319     const std::string &plmn, const bool showSpn, const std::string &spn)
320 {
321     Want want;
322     want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SPN_INFO_CHANGED);
323     want.SetParam(CUR_SLOT_ID, slotId_);
324     want.SetParam(CUR_PLMN_SHOW, showPlmn);
325     want.SetParam(CUR_PLMN, plmn);
326     want.SetParam(CUR_SPN_SHOW, showSpn);
327     want.SetParam(CUR_SPN, spn);
328     CommonEventData data;
329     data.SetWant(want);
330 
331     CommonEventPublishInfo publishInfo;
332     publishInfo.SetSticky(true);
333     bool publishResult = CommonEventManager::PublishCommonEvent(data, publishInfo, nullptr);
334     TELEPHONY_LOGI("OperatorName::PublishEvent result : %{public}d slotId:%{public}d", publishResult, slotId_);
335     if (publishResult) {
336         curRegState_ = state;
337         curSpnRule_ = rule;
338         curSpn_ = spn;
339         curSpnShow_ = showSpn;
340         curPlmn_ = plmn;
341         curPlmnShow_ = showPlmn;
342     }
343 }
344 
GetPlmn(const sptr<NetworkState> & networkState,bool longNameRequired)345 std::string OperatorName::GetPlmn(const sptr<NetworkState> &networkState, bool longNameRequired)
346 {
347     if (networkState == nullptr) {
348         TELEPHONY_LOGE("OperatorName::GetPlmn networkState is nullptr slotId:%{public}d", slotId_);
349         return "";
350     }
351     std::string plmn = "";
352     std::string numeric = networkState->GetPlmnNumeric();
353     bool roaming = networkState->IsRoaming();
354     int32_t lac = GetCurrentLac();
355     plmn = GetCustomName(numeric);
356     if (plmn.empty()) {
357         plmn = GetCustEons(numeric, lac, roaming, longNameRequired);
358     }
359     if (plmn.empty()) {
360         plmn = GetEons(numeric, lac, longNameRequired);
361     }
362     if (plmn.empty()) {
363         plmn = networkState->GetLongOperatorName();
364     }
365     TELEPHONY_LOGD(
366         "OperatorName::GetPlmn lac:%{public}d, numeric:%{public}s, longNameRequired:%{public}d, plmn:%{public}s", lac,
367         numeric.c_str(), longNameRequired, plmn.c_str());
368     return plmn;
369 }
370 
GetEons(const std::string & numeric,int32_t lac,bool longNameRequired)371 std::string OperatorName::GetEons(const std::string &numeric, int32_t lac, bool longNameRequired)
372 {
373     if (simManager_ == nullptr) {
374         TELEPHONY_LOGE("OperatorName::GetEons simManager_ is nullptr slotId:%{public}d", slotId_);
375         return "";
376     }
377     return Str16ToStr8(simManager_->GetSimEons(slotId_, numeric, lac, longNameRequired));
378 }
379 
GetCustSpnRule(bool roaming)380 unsigned int OperatorName::GetCustSpnRule(bool roaming)
381 {
382     unsigned int cond = 0;
383     if (displayConditionCust_ <= SPN_INVALID) {
384         return cond;
385     }
386     if (roaming) {
387         cond = SPN_CONDITION_DISPLAY_PLMN;
388         if ((static_cast<unsigned int>(displayConditionCust_) & static_cast<unsigned int>(SPN_COND)) == 0) {
389             cond |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_SPN);
390         }
391     } else {
392         cond = SPN_CONDITION_DISPLAY_SPN;
393         if ((static_cast<unsigned int>(displayConditionCust_) & static_cast<unsigned int>(SPN_COND_PLMN)) ==
394             SPN_COND_PLMN) {
395             cond |= static_cast<unsigned int>(SPN_CONDITION_DISPLAY_PLMN);
396         }
397     }
398     return cond;
399 }
400 
GetCustEons(const std::string & numeric,int32_t lac,bool roaming,bool longNameRequired)401 std::string OperatorName::GetCustEons(const std::string &numeric, int32_t lac, bool roaming, bool longNameRequired)
402 {
403     if (!enableCust_ || numeric.empty() || pnnCust_.empty() || (oplCust_.empty() && roaming)) {
404         TELEPHONY_LOGI("OperatorName::GetCustEons is empty");
405         return "";
406     }
407     int32_t pnnIndex = 1;
408     for (std::shared_ptr<OperatorPlmnInfo> opl : oplCust_) {
409         if (opl == nullptr) {
410             continue;
411         }
412         pnnIndex = -1;
413         TELEPHONY_LOGI(
414             "OperatorName::GetCustEons numeric:%{public}s, opl->plmnNumeric:%{public}s, lac:%{public}d, "
415             "opl->lacStart:%{public}d, opl->lacEnd:%{public}d, opl->pnnRecordId:%{public}d",
416             numeric.c_str(), opl->plmnNumeric.c_str(), lac, opl->lacStart, opl->lacEnd, opl->pnnRecordId);
417         if (numeric.compare(opl->plmnNumeric) == 0 &&
418             ((opl->lacStart == 0 && opl->lacEnd == 0xfffe) || (opl->lacStart <= lac && opl->lacEnd >= lac))) {
419             pnnIndex = opl->pnnRecordId;
420             break;
421         }
422     }
423     TELEPHONY_LOGI("OperatorName::GetCustEons pnnIndex:%{public}d", pnnIndex);
424     std::string custEonsName = "";
425     if (pnnIndex >= 1 && pnnIndex <= (int32_t)pnnCust_.size()) {
426         TELEPHONY_LOGI(
427             "OperatorName::GetCustEons longNameRequired:%{public}d, longName:%{public}s, shortName:%{public}s,",
428             longNameRequired, pnnCust_.at(pnnIndex - 1)->longName.c_str(),
429             pnnCust_.at(pnnIndex - 1)->shortName.c_str());
430         if (longNameRequired) {
431             custEonsName = pnnCust_.at(pnnIndex - 1)->longName;
432         } else {
433             custEonsName = pnnCust_.at(pnnIndex - 1)->shortName;
434         }
435     }
436     return custEonsName;
437 }
438 
GetCustomName(const std::string & numeric)439 std::string OperatorName::GetCustomName(const std::string &numeric)
440 {
441     TELEPHONY_LOGD("OperatorName::GetCustomName numeric:%{public}s", numeric.c_str());
442     std::string name = "";
443     if (numeric.empty()) {
444         return name;
445     }
446     auto obj = std::find(cmMccMnc_.begin(), cmMccMnc_.end(), numeric);
447     if (obj != cmMccMnc_.end()) {
448         ResourceUtils::Get().GetValueByName<std::string>(ResourceUtils::CMCC, name);
449         TELEPHONY_LOGD("OperatorName::GetCustomName CMCC:%{public}s", name.c_str());
450         return name;
451     }
452     obj = std::find(cuMccMnc_.begin(), cuMccMnc_.end(), numeric);
453     if (obj != cuMccMnc_.end()) {
454         ResourceUtils::Get().GetValueByName<std::string>(ResourceUtils::CUCC, name);
455         TELEPHONY_LOGD("OperatorName::GetCustomName CUCC:%{public}s", name.c_str());
456         return name;
457     }
458     obj = std::find(ctMccMnc_.begin(), ctMccMnc_.end(), numeric);
459     if (obj != ctMccMnc_.end()) {
460         ResourceUtils::Get().GetValueByName<std::string>(ResourceUtils::CTCC, name);
461         TELEPHONY_LOGD("OperatorName::GetCustomName CTCC:%{public}s", name.c_str());
462         return name;
463     }
464     return name;
465 }
466 
GetCurrentLac()467 int32_t OperatorName::GetCurrentLac()
468 {
469     auto networkSearchManager = networkSearchManager_.lock();
470     if (networkSearchManager == nullptr) {
471         TELEPHONY_LOGE("OperatorName::GetCurrentLac networkSearchManager is nullptr slotId:%{public}d", slotId_);
472         return 0;
473     }
474     sptr<CellLocation> location = networkSearchManager->GetCellLocation(slotId_);
475     if (location == nullptr) {
476         TELEPHONY_LOGE("OperatorName::GetCurrentLac location is nullptr slotId:%{public}d", slotId_);
477         return 0;
478     }
479     if (location->GetCellLocationType() != CellLocation::CellType::CELL_TYPE_GSM) {
480         TELEPHONY_LOGE("OperatorName::GetCurrentLac location type isn't GSM slotId:%{public}d", slotId_);
481         return 0;
482     }
483     sptr<GsmCellLocation> gsmLocation = sptr<GsmCellLocation>(static_cast<GsmCellLocation *>(location.GetRefPtr()));
484     if (gsmLocation == nullptr) {
485         TELEPHONY_LOGE("OperatorName::GetCurrentLac gsmLocation is nullptr slotId:%{public}d", slotId_);
486         return 0;
487     }
488     return gsmLocation->GetLac();
489 }
490 
UpdateOperatorConfig()491 void OperatorName::UpdateOperatorConfig()
492 {
493     OperatorConfig operatorConfig;
494     CoreManagerInner::GetInstance().GetOperatorConfigs(slotId_, operatorConfig);
495     if (operatorConfig.boolValue.find(KEY_ENABLE_OPERATOR_NAME_CUST_BOOL) != operatorConfig.boolValue.end()) {
496         enableCust_ = operatorConfig.boolValue[KEY_ENABLE_OPERATOR_NAME_CUST_BOOL];
497     }
498     if (operatorConfig.stringValue.find(KEY_OPERATOR_NAME_CUST_STRING) != operatorConfig.stringValue.end()) {
499         spnCust_ = operatorConfig.stringValue[KEY_OPERATOR_NAME_CUST_STRING];
500     }
501     if (operatorConfig.intValue.find(KEY_SPN_DISPLAY_CONDITION_CUST_INT) != operatorConfig.intValue.end()) {
502         displayConditionCust_ = operatorConfig.intValue[KEY_SPN_DISPLAY_CONDITION_CUST_INT];
503     }
504     if (operatorConfig.stringArrayValue.find(KEY_PNN_CUST_STRING_ARRAY) != operatorConfig.stringArrayValue.end()) {
505         UpdatePnnCust(operatorConfig.stringArrayValue[KEY_PNN_CUST_STRING_ARRAY]);
506     }
507     if (operatorConfig.stringArrayValue.find(KEY_OPL_CUST_STRING_ARRAY) != operatorConfig.stringArrayValue.end()) {
508         UpdateOplCust(operatorConfig.stringArrayValue[KEY_OPL_CUST_STRING_ARRAY]);
509     }
510 }
511 
UpdatePnnCust(const std::vector<std::string> & pnnCust)512 void OperatorName::UpdatePnnCust(const std::vector<std::string> &pnnCust)
513 {
514     pnnCust_.clear();
515     if (pnnCust.empty()) {
516         TELEPHONY_LOGE("OperatorName::UpdatePnnCust pnnCust is empty slotId:%{public}d", slotId_);
517         return;
518     }
519     for (const auto &data : pnnCust) {
520         TELEPHONY_LOGI("OperatorName::UpdatePnnCust: %{public}s", data.c_str());
521         std::vector<std::string> pnnString = NetworkUtils::SplitString(data, ",");
522         if (pnnString.size() != PNN_CUST_STRING_SIZE) {
523             continue;
524         }
525         std::shared_ptr<PlmnNetworkName> pnn = std::make_shared<PlmnNetworkName>();
526         pnn->shortName = pnnString.back();
527         pnnString.pop_back();
528         pnn->longName = pnnString.back();
529         if (!pnn->longName.empty() || !pnn->shortName.empty()) {
530             pnnCust_.push_back(pnn);
531         }
532     }
533 }
534 
UpdateOplCust(const std::vector<std::string> & oplCust)535 void OperatorName::UpdateOplCust(const std::vector<std::string> &oplCust)
536 {
537     oplCust_.clear();
538     if (oplCust.empty()) {
539         TELEPHONY_LOGE("OperatorName::UpdateOplCust oplCust is empty slotId:%{public}d", slotId_);
540         return;
541     }
542     for (const auto &data : oplCust) {
543         TELEPHONY_LOGI("OperatorName::UpdateOplCust: %{public}s", data.c_str());
544         std::vector<std::string> oplString = NetworkUtils::SplitString(data, ",");
545         if (oplString.size() != OPL_CUST_STRING_SIZE || oplString.back().empty()) {
546             continue;
547         }
548         std::shared_ptr<OperatorPlmnInfo> opl = std::make_shared<OperatorPlmnInfo>();
549         int32_t base = 16; // convert to hexadecimal
550         opl->pnnRecordId = stoi(oplString.back(), 0, base);
551         oplString.pop_back();
552         if (oplString.back().empty()) {
553             continue;
554         }
555         opl->lacEnd = stoi(oplString.back(), 0, base);
556         oplString.pop_back();
557         if (oplString.back().empty()) {
558             continue;
559         }
560         opl->lacStart = stoi(oplString.back(), 0, base);
561         oplString.pop_back();
562         opl->plmnNumeric = oplString.back();
563         if (!opl->plmnNumeric.empty()) {
564             oplCust_.push_back(opl);
565         }
566     }
567 }
568 } // namespace Telephony
569 } // namespace OHOS
570