• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "cell_info.h"
17 #include "telephony_log_wrapper.h"
18 #include "network_search_manager.h"
19 #include "network_search_notify.h"
20 
21 namespace OHOS {
22 namespace Telephony {
23 constexpr int32_t ZERO_VALUE = 0;
24 constexpr int32_t SIGNAL_LEVEL_INVALID = 0;
25 constexpr int32_t SIGNAL_RSSI_MAXIMUM = -1;
26 constexpr int32_t SIGNAL_FOUR_BARS = 4;
27 constexpr int32_t SIGNAL_FIVE_BARS = 5;
28 const int32_t *GSM_SIGNAL_THRESHOLD = SignalInformation::GSM_SIGNAL_THRESHOLD_5BAR;
29 const int32_t *CDMA_SIGNAL_THRESHOLD = SignalInformation::CDMA_SIGNAL_THRESHOLD_5BAR;
30 const int32_t *LTE_SIGNAL_THRESHOLD = SignalInformation::LTE_SIGNAL_THRESHOLD_5BAR;
31 const int32_t *WCDMA_SIGNAL_THRESHOLD = SignalInformation::WCDMA_SIGNAL_THRESHOLD_5BAR;
32 const int32_t *TD_SCDMA_SIGNAL_THRESHOLD = SignalInformation::TD_SCDMA_SIGNAL_THRESHOLD_5BAR;
33 const int32_t *NR_SIGNAL_THRESHOLD = SignalInformation::NR_SIGNAL_THRESHOLD_5BAR;
34 int32_t CellInfo::signalBar_ = SIGNAL_FIVE_BARS;
35 
36 const std::map<TelRilRatType, CellInfo::CallInfoFunc> CellInfo::memberFuncMap_ = {
37     { TelRilRatType::NETWORK_TYPE_GSM,
__anon9c4507380102() 38         [](CellInfo *ci, CellNearbyInfo *cellInfo) { return ci->ProcessNeighboringCellGsm(cellInfo); } },
39     { TelRilRatType::NETWORK_TYPE_CDMA,
__anon9c4507380202() 40         [](CellInfo *ci, CellNearbyInfo *cellInfo) { return ci->ProcessNeighboringCellCdma(cellInfo); } },
41     { TelRilRatType::NETWORK_TYPE_WCDMA,
__anon9c4507380302() 42         [](CellInfo *ci, CellNearbyInfo *cellInfo) { return ci->ProcessNeighboringCellWcdma(cellInfo); } },
43     { TelRilRatType::NETWORK_TYPE_TDSCDMA,
__anon9c4507380402() 44         [](CellInfo *ci, CellNearbyInfo *cellInfo) { return ci->ProcessNeighboringCellTdscdma(cellInfo); } },
45     { TelRilRatType::NETWORK_TYPE_LTE,
__anon9c4507380502() 46         [](CellInfo *ci, CellNearbyInfo *cellInfo) { return ci->ProcessNeighboringCellLte(cellInfo); } },
47     { TelRilRatType::NETWORK_TYPE_NR,
__anon9c4507380602() 48         [](CellInfo *ci, CellNearbyInfo *cellInfo) { return ci->ProcessNeighboringCellNr(cellInfo); } }
49 };
50 
CellInfo(std::weak_ptr<NetworkSearchManager> networkSearchManager,int32_t slotId)51 CellInfo::CellInfo(std::weak_ptr<NetworkSearchManager> networkSearchManager, int32_t slotId)
52     : networkSearchManager_(networkSearchManager), slotId_(slotId)
53 {
54     InitCellSignalBar();
55 }
56 
InitCellSignalBar(const int32_t bar)57 void CellInfo::InitCellSignalBar(const int32_t bar)
58 {
59     if (bar == SIGNAL_FOUR_BARS) {
60         GSM_SIGNAL_THRESHOLD = SignalInformation::GSM_SIGNAL_THRESHOLD_4BAR;
61         CDMA_SIGNAL_THRESHOLD = SignalInformation::CDMA_SIGNAL_THRESHOLD_4BAR;
62         LTE_SIGNAL_THRESHOLD = SignalInformation::LTE_SIGNAL_THRESHOLD_4BAR;
63         WCDMA_SIGNAL_THRESHOLD = SignalInformation::WCDMA_SIGNAL_THRESHOLD_4BAR;
64         TD_SCDMA_SIGNAL_THRESHOLD = SignalInformation::TD_SCDMA_SIGNAL_THRESHOLD_4BAR;
65         NR_SIGNAL_THRESHOLD = SignalInformation::NR_SIGNAL_THRESHOLD_4BAR;
66         signalBar_ = SIGNAL_FOUR_BARS;
67     } else {
68         GSM_SIGNAL_THRESHOLD = SignalInformation::GSM_SIGNAL_THRESHOLD_5BAR;
69         CDMA_SIGNAL_THRESHOLD = SignalInformation::CDMA_SIGNAL_THRESHOLD_5BAR;
70         LTE_SIGNAL_THRESHOLD = SignalInformation::LTE_SIGNAL_THRESHOLD_5BAR;
71         WCDMA_SIGNAL_THRESHOLD = SignalInformation::WCDMA_SIGNAL_THRESHOLD_5BAR;
72         TD_SCDMA_SIGNAL_THRESHOLD = SignalInformation::TD_SCDMA_SIGNAL_THRESHOLD_5BAR;
73         NR_SIGNAL_THRESHOLD = SignalInformation::NR_SIGNAL_THRESHOLD_5BAR;
74         signalBar_ = SIGNAL_FIVE_BARS;
75     }
76 }
77 
ProcessNeighboringCellInfo(const AppExecFwk::InnerEvent::Pointer & event)78 void CellInfo::ProcessNeighboringCellInfo(const AppExecFwk::InnerEvent::Pointer &event)
79 {
80     TELEPHONY_LOGD("CellInfo::ProcessNeighboringCellInfo cell info start...... slotId:%{public}d", slotId_);
81     std::lock_guard<ffrt::mutex> lock(mutex_);
82     if (event == nullptr) {
83         TELEPHONY_LOGE("CellInfo::ProcessNeighboringCellInfo event is nullptr slotId:%{public}d", slotId_);
84         return;
85     }
86 
87     CellListNearbyInfo *cellInfo = event->GetSharedObject<CellListNearbyInfo>().get();
88     if (cellInfo == nullptr) {
89         TELEPHONY_LOGE("CellInfo::ProcessNeighboringCellInfo rssi is nullptr slotId:%{public}d", slotId_);
90         return;
91     }
92 
93     int32_t cellSize = cellInfo->itemNum >= CellInformation::MAX_CELL_NUM ? CellInformation::MAX_CELL_NUM :
94                                                                             cellInfo->itemNum;
95     if (cellSize > 0) {
96         neighboringCellInfos_.clear();
97     } else {
98         return;
99     }
100 
101     TELEPHONY_LOGI(
102         "CellInfo::ProcessNeighboringCellInfo cell size:%{public}d, cur size:%{public}zu slotId:%{public}d",
103         cellInfo->itemNum, cellInfos_.size(), slotId_);
104     std::vector<CellNearbyInfo> cell = cellInfo->cellNearbyInfo;
105     for (int32_t i = 0; i < cellSize; ++i) {
106         int32_t type = cell[i].ratType;
107         auto itFunc = memberFuncMap_.find(static_cast<TelRilRatType>(type));
108         if (itFunc != memberFuncMap_.end()) {
109             auto memberFunc = itFunc->second;
110             if (memberFunc != nullptr) {
111                 memberFunc(this, &cell[i]);
112             }
113         }
114     }
115 }
116 
ProcessCurrentCellInfo(const AppExecFwk::InnerEvent::Pointer & event)117 void CellInfo::ProcessCurrentCellInfo(const AppExecFwk::InnerEvent::Pointer &event)
118 {
119     ClearCellInfoList();
120     std::lock_guard<ffrt::mutex> lock(mutex_);
121     if (event == nullptr) {
122         TELEPHONY_LOGE("CellInfo::ProcessCurrentCellInfo event is nullptr slotId:%{public}d", slotId_);
123         return;
124     }
125     std::shared_ptr<CellListCurrentInformation> cellInformationList =
126         event->GetSharedObject<CellListCurrentInformation>();
127     CellListCurrentInformation *cellInfoList = cellInformationList.get();
128     if (cellInfoList == nullptr) {
129         TELEPHONY_LOGE("CellInfo::ProcessCurrentCellInfo cellInfoList is nullptr slotId:%{public}d", slotId_);
130         return;
131     }
132 
133     int32_t cellSize = cellInfoList->itemNum >= CellInformation::MAX_CELL_NUM ? CellInformation::MAX_CELL_NUM :
134                                                                                 cellInfoList->itemNum;
135     if (cellSize <= 0) {
136         TELEPHONY_LOGE("CellInfo::ProcessCurrentCellInfo cellSize:%{public}d error, slotId:%{public}d",
137             cellSize, slotId_);
138         return;
139     }
140 
141     TELEPHONY_LOGI("CellInfo::ProcessCurrentCellInfo cell size:%{public}d, slotId:%{public}d",
142         cellInfoList->itemNum, slotId_);
143     std::vector<CurrentCellInformation> cell = cellInfoList->cellCurrentInfo;
144     for (int32_t i = 0; i < cellSize; ++i) {
145         CurrentCellInformation currentCell = cell[i];
146         ProcessCurrentCell(&currentCell);
147     }
148     NotifyCellInfoUpdated();
149 }
150 
NotifyCellInfoUpdated() const151 void CellInfo::NotifyCellInfoUpdated() const
152 {
153     if (cellInfos_.size() > 0) {
154         DelayedSingleton<NetworkSearchNotify>::GetInstance()->NotifyCellInfoUpdated(slotId_, cellInfos_);
155     } else {
156         TELEPHONY_LOGI("CellInfo::NotifyCellInfoUpdated no notify slotId:%{public}d", slotId_);
157     }
158 }
159 
UpdateCellLocation(int32_t techType,int32_t cellId,int32_t lac)160 void CellInfo::UpdateCellLocation(int32_t techType, int32_t cellId, int32_t lac)
161 {
162     CellInformation::CellType type = ConvertTechToCellType(static_cast<RadioTech>(techType));
163     if (type == CellInformation::CellType::CELL_TYPE_NONE) {
164         TELEPHONY_LOGE("CellInfo::UpdateCellLocation type error");
165         return;
166     }
167 
168     for (auto &cell : cellInfos_) {
169         if (cell->GetNetworkType() == type) {
170             if (ProcessCellLocation(cell, type, cellId, lac)) {
171                 UpdateSignalLevel(cell, type);
172                 NotifyCellInfoUpdated();
173                 cell->SetIsCamped(true);
174                 std::lock_guard<ffrt::mutex> lock(mutex_);
175                 currentCellInfo_ = cell;
176             }
177             break;
178         }
179     }
180 }
181 
ProcessCellLocation(sptr<CellInformation> & cell,CellInformation::CellType type,int32_t cellId,int32_t lac)182 bool CellInfo::ProcessCellLocation(
183     sptr<CellInformation> &cell, CellInformation::CellType type, int32_t cellId, int32_t lac)
184 {
185     switch (type) {
186         case CellInformation::CellType::CELL_TYPE_GSM: {
187             GsmCellInformation *gsm = reinterpret_cast<GsmCellInformation *>(cell.GetRefPtr());
188             if (gsm->GetCellId() != cellId || gsm->GetLac() != lac) {
189                 gsm->UpdateLocation(cellId, lac);
190                 return true;
191             }
192             break;
193         }
194         case CellInformation::CellType::CELL_TYPE_LTE: {
195             LteCellInformation *lte = reinterpret_cast<LteCellInformation *>(cell.GetRefPtr());
196             if (lte->GetCellId() != cellId || lte->GetTac() != lac) {
197                 lte->UpdateLocation(cellId, lac);
198                 return true;
199             }
200             break;
201         }
202         case CellInformation::CellType::CELL_TYPE_WCDMA: {
203             WcdmaCellInformation *wcdma = reinterpret_cast<WcdmaCellInformation *>(cell.GetRefPtr());
204             if (wcdma->GetCellId() != cellId || wcdma->GetLac() != lac) {
205                 wcdma->UpdateLocation(cellId, lac);
206                 return true;
207             }
208             break;
209         }
210         case CellInformation::CellType::CELL_TYPE_TDSCDMA: {
211             TdscdmaCellInformation *tdscdma = reinterpret_cast<TdscdmaCellInformation *>(cell.GetRefPtr());
212             if (tdscdma->GetCellId() != cellId || tdscdma->GetLac() != lac) {
213                 tdscdma->UpdateLocation(cellId, lac);
214                 return true;
215             }
216             break;
217         }
218         case CellInformation::CellType::CELL_TYPE_NR: {
219             NrCellInformation *nr = reinterpret_cast<NrCellInformation *>(cell.GetRefPtr());
220             if (nr->GetCellId() != cellId || nr->GetTac() != lac) {
221                 nr->UpdateLocation(cellId, lac);
222                 return true;
223             }
224             break;
225         }
226         default:
227             TELEPHONY_LOGE("CellInfo::ProcessCellLocation type error");
228             break;
229     }
230     return false;
231 }
232 
UpdateSignalLevel(sptr<CellInformation> & cell,CellInformation::CellType cellType)233 void CellInfo::UpdateSignalLevel(sptr<CellInformation> &cell, CellInformation::CellType cellType)
234 {
235     if (cellType == CellInformation::CellType::CELL_TYPE_NONE || cell->GetNetworkType() != cellType) {
236         TELEPHONY_LOGE("CellInfo::UpdateSignalLevel type error");
237         return;
238     }
239 
240     std::shared_ptr<NetworkSearchManager> nsm = networkSearchManager_.lock();
241     if (nsm == nullptr) {
242         TELEPHONY_LOGE("CellInfo::UpdateSignalLevel nsm is nullptr slotId:%{public}d", slotId_);
243         return;
244     }
245 
246     std::vector<sptr<SignalInformation>> signals;
247     nsm->GetSignalInfoList(slotId_, signals);
248     int32_t signalLevel = 0;
249     int32_t signalIntensity = 0;
250     for (const auto &v : signals) {
251         if (ConvertToCellType(v->GetNetworkType()) == cellType) {
252             TELEPHONY_LOGI("CellInfo::UpdateSignalLevel signal level %{public}d slotId:%{public}d",
253                 v->GetSignalLevel(), slotId_);
254             signalLevel = v->GetSignalLevel();
255             signalIntensity = v->GetSignalIntensity();
256             break;
257         }
258     }
259     cell->SetSignalLevel(signalLevel);
260     cell->SetSignalIntensity(signalIntensity);
261 }
262 
ConvertToCellType(SignalInformation::NetworkType signalType) const263 CellInformation::CellType CellInfo::ConvertToCellType(SignalInformation::NetworkType signalType) const
264 {
265     switch (signalType) {
266         case SignalInformation::NetworkType::GSM:
267             return CellInformation::CellType::CELL_TYPE_GSM;
268         case SignalInformation::NetworkType::WCDMA:
269             return CellInformation::CellType::CELL_TYPE_WCDMA;
270         case SignalInformation::NetworkType::LTE:
271             return CellInformation::CellType::CELL_TYPE_LTE;
272         case SignalInformation::NetworkType::CDMA:
273             return CellInformation::CellType::CELL_TYPE_CDMA;
274         case SignalInformation::NetworkType::TDSCDMA:
275             return CellInformation::CellType::CELL_TYPE_TDSCDMA;
276         case SignalInformation::NetworkType::NR:
277             return CellInformation::CellType::CELL_TYPE_NR;
278         default:
279             return CellInformation::CellType::CELL_TYPE_NONE;
280     }
281 }
282 
ConvertRatToCellType(int ratType) const283 CellInformation::CellType CellInfo::ConvertRatToCellType(int ratType) const
284 {
285     switch (ratType) {
286         case TelRilRatType::NETWORK_TYPE_GSM:
287             return CellInformation::CellType::CELL_TYPE_GSM;
288         case TelRilRatType::NETWORK_TYPE_WCDMA:
289             return CellInformation::CellType::CELL_TYPE_WCDMA;
290         case TelRilRatType::NETWORK_TYPE_LTE:
291             return CellInformation::CellType::CELL_TYPE_LTE;
292         case TelRilRatType::NETWORK_TYPE_CDMA:
293             return CellInformation::CellType::CELL_TYPE_CDMA;
294         case TelRilRatType::NETWORK_TYPE_TDSCDMA:
295             return CellInformation::CellType::CELL_TYPE_TDSCDMA;
296         case TelRilRatType::NETWORK_TYPE_NR:
297             return CellInformation::CellType::CELL_TYPE_NR;
298         default:
299             return CellInformation::CellType::CELL_TYPE_NONE;
300     }
301 }
302 
ConvertTechToCellType(RadioTech techType) const303 CellInformation::CellType CellInfo::ConvertTechToCellType(RadioTech techType) const
304 {
305     switch (techType) {
306         case RadioTech::RADIO_TECHNOLOGY_GSM:
307             return CellInformation::CellType::CELL_TYPE_GSM;
308         case RadioTech::RADIO_TECHNOLOGY_WCDMA:
309         case RadioTech::RADIO_TECHNOLOGY_HSPAP:
310         case RadioTech::RADIO_TECHNOLOGY_HSPA:
311             return CellInformation::CellType::CELL_TYPE_WCDMA;
312         case RadioTech::RADIO_TECHNOLOGY_LTE:
313         case RadioTech::RADIO_TECHNOLOGY_LTE_CA:
314             return CellInformation::CellType::CELL_TYPE_LTE;
315         case RadioTech::RADIO_TECHNOLOGY_TD_SCDMA:
316             return CellInformation::CellType::CELL_TYPE_TDSCDMA;
317         case RadioTech::RADIO_TECHNOLOGY_1XRTT:
318         case RadioTech::RADIO_TECHNOLOGY_EVDO:
319         case RadioTech::RADIO_TECHNOLOGY_EHRPD:
320             return CellInformation::CellType::CELL_TYPE_CDMA;
321         case RadioTech::RADIO_TECHNOLOGY_NR:
322             return CellInformation::CellType::CELL_TYPE_NR;
323         default:
324             return CellInformation::CellType::CELL_TYPE_NONE;
325     }
326 }
327 
ProcessCurrentCell(CurrentCellInformation * cellInfo)328 bool CellInfo::ProcessCurrentCell(CurrentCellInformation *cellInfo)
329 {
330     bool ret = false;
331     switch (cellInfo->ratType) {
332         case TelRilRatType::NETWORK_TYPE_GSM: {
333             ret = ProcessCurrentCellGsm(cellInfo);
334             break;
335         }
336         case TelRilRatType::NETWORK_TYPE_LTE: {
337             ret = ProcessCurrentCellLte(cellInfo);
338             break;
339         }
340         case TelRilRatType::NETWORK_TYPE_WCDMA: {
341             ret = ProcessCurrentCellWcdma(cellInfo);
342             break;
343         }
344         case TelRilRatType::NETWORK_TYPE_TDSCDMA: {
345             ret = ProcessCurrentCellTdscdma(cellInfo);
346             break;
347         }
348         case TelRilRatType::NETWORK_TYPE_CDMA: {
349             ret = ProcessCurrentCellCdma(cellInfo);
350             break;
351         }
352         case TelRilRatType::NETWORK_TYPE_NR: {
353             ret = ProcessCurrentCellNr(cellInfo);
354             break;
355         }
356         default: {
357             TELEPHONY_LOGI("CellInfo::ProcessCurrentCell error rat type:%{public}d slotId:%{public}d",
358                 cellInfo->ratType, slotId_);
359             return false;
360         }
361     }
362     if (!ret) {
363         TELEPHONY_LOGI(
364             "CellInfo::ProcessCurrentCell currentCellInfo is null or cell info no change slotId:%{public}d",
365             slotId_);
366         return false;
367     }
368     return true;
369 }
370 
ProcessNeighboringCellGsm(CellNearbyInfo * cellInfo)371 bool CellInfo::ProcessNeighboringCellGsm(CellNearbyInfo *cellInfo)
372 {
373     bool ret = false;
374     if (cellInfo == nullptr) {
375         TELEPHONY_LOGE("cellInfo is nullptr");
376         return ret;
377     }
378     sptr<GsmCellInformation> cell = new GsmCellInformation;
379     if (cell != nullptr) {
380         int32_t &arfcn = cellInfo->ServiceCellParas.gsm.arfcn;
381         int32_t &cellId = cellInfo->ServiceCellParas.gsm.cellId;
382         int32_t &bsic = cellInfo->ServiceCellParas.gsm.bsic;
383         int32_t &lac = cellInfo->ServiceCellParas.gsm.lac;
384         int32_t &rxlev = cellInfo->ServiceCellParas.gsm.rxlev;
385         rxlev = ZERO_VALUE - rxlev;
386         cell->Init(0, 0, cellId);
387         cell->SetGsmParam(bsic, lac, arfcn);
388         cell->SetSignalIntensity(rxlev);
389         neighboringCellInfos_.emplace_back(cell);
390         TELEPHONY_LOGI("CellInfo::ProcessNeighboringCellGsm arfcn:%{private}d cellId:%{private}d"
391             "bsic:%{private}d lac:%{private}d slotId:%{public}d",
392             arfcn, cellId, bsic, lac, slotId_);
393         ret = true;
394     }
395     return ret;
396 }
397 
ProcessNeighboringCellLte(CellNearbyInfo * cellInfo)398 bool CellInfo::ProcessNeighboringCellLte(CellNearbyInfo *cellInfo)
399 {
400     bool ret = false;
401     if (cellInfo == nullptr) {
402         TELEPHONY_LOGE("cellInfo is nullptr");
403         return ret;
404     }
405     sptr<LteCellInformation> cell = new LteCellInformation;
406     if (cell != nullptr) {
407         int32_t &arfcn = cellInfo->ServiceCellParas.lte.arfcn;
408         int32_t pci = cellInfo->ServiceCellParas.lte.pci;
409         int32_t &rsrp = cellInfo->ServiceCellParas.lte.rsrp;
410         rsrp = ZERO_VALUE - rsrp;
411         cell->Init(0, 0, 0);
412         cell->SetLteParam(pci, 0, arfcn);
413         cell->SetSignalIntensity(rsrp);
414         neighboringCellInfos_.emplace_back(cell);
415         TELEPHONY_LOGI("CellInfo::ProcessLte arfcn:%{private}d pci:%{private}d slotId:%{public}d", arfcn, pci, slotId_);
416         ret = true;
417     }
418     return ret;
419 }
420 
ProcessNeighboringCellWcdma(CellNearbyInfo * cellInfo)421 bool CellInfo::ProcessNeighboringCellWcdma(CellNearbyInfo *cellInfo)
422 {
423     bool ret = false;
424     if (cellInfo == nullptr) {
425         TELEPHONY_LOGE("cellInfo is nullptr");
426         return ret;
427     }
428     sptr<WcdmaCellInformation> cell = new WcdmaCellInformation;
429     if (cell != nullptr) {
430         int32_t &arfcn = cellInfo->ServiceCellParas.wcdma.arfcn;
431         int32_t psc = cellInfo->ServiceCellParas.wcdma.psc;
432         int32_t &rscp = cellInfo->ServiceCellParas.wcdma.rscp;
433         rscp = ZERO_VALUE - rscp;
434         cell->Init(0, 0, 0);
435         cell->SetWcdmaParam(psc, 0, arfcn);
436         cell->SetSignalIntensity(rscp);
437         neighboringCellInfos_.emplace_back(cell);
438         TELEPHONY_LOGI(
439             "CellInfo::ProcessWcdma arfcn:%{private}d psc:%{private}d slotId:%{public}d", arfcn, psc, slotId_);
440         ret = true;
441     }
442     return ret;
443 }
444 
ProcessNeighboringCellCdma(CellNearbyInfo * cellInfo)445 bool CellInfo::ProcessNeighboringCellCdma(CellNearbyInfo *cellInfo)
446 {
447     bool ret = false;
448     if (cellInfo == nullptr) {
449         TELEPHONY_LOGE("cellInfo is nullptr");
450         return ret;
451     }
452     sptr<CdmaCellInformation> cell = new CdmaCellInformation;
453     if (cell != nullptr) {
454         int32_t &baseId = cellInfo->ServiceCellParas.cdma.baseId;
455         int32_t &longitude = cellInfo->ServiceCellParas.cdma.longitude;
456         int32_t &latitude = cellInfo->ServiceCellParas.cdma.latitude;
457         int32_t &networkId = cellInfo->ServiceCellParas.cdma.networkId;
458         int32_t &systemId = cellInfo->ServiceCellParas.cdma.systemId;
459         int32_t &pilotStrength = cellInfo->ServiceCellParas.cdma.pilotStrength;
460         pilotStrength = ZERO_VALUE - pilotStrength;
461         cell->Init(0, 0, 0);
462         cell->SetCdmaParam(baseId, latitude, longitude, networkId, systemId);
463         cell->SetSignalIntensity(pilotStrength);
464         neighboringCellInfos_.emplace_back(cell);
465         TELEPHONY_LOGI(
466             "CellInfo::ProcessCdma baseId:%{private}d psc:%{private}d slotId:%{public}d", baseId, systemId, slotId_);
467         ret = true;
468     }
469     return ret;
470 }
471 
ProcessNeighboringCellTdscdma(CellNearbyInfo * cellInfo)472 bool CellInfo::ProcessNeighboringCellTdscdma(CellNearbyInfo *cellInfo)
473 {
474     bool ret = false;
475     if (cellInfo == nullptr) {
476         TELEPHONY_LOGE("cellInfo is nullptr");
477         return ret;
478     }
479     sptr<TdscdmaCellInformation> cell = new TdscdmaCellInformation;
480     if (cell != nullptr) {
481         int32_t &arfcn = cellInfo->ServiceCellParas.tdscdma.arfcn;
482         int32_t &cpid = cellInfo->ServiceCellParas.tdscdma.cpid;
483         int32_t &lac = cellInfo->ServiceCellParas.tdscdma.lac;
484         int32_t &rscp = cellInfo->ServiceCellParas.tdscdma.rscp;
485         rscp = ZERO_VALUE - rscp;
486         cell->Init(0, 0, 0);
487         cell->SetTdscdmaParam(cpid, lac, arfcn);
488         cell->SetSignalIntensity(rscp);
489         neighboringCellInfos_.emplace_back(cell);
490         TELEPHONY_LOGI(
491             "CellInfo::ProcessTdscdma arfcn:%{private}d psc:%{private}d slotId:%{public}d", arfcn, cpid, slotId_);
492         ret = true;
493     }
494     return ret;
495 }
496 
ProcessNeighboringCellNr(CellNearbyInfo * cellInfo)497 bool CellInfo::ProcessNeighboringCellNr(CellNearbyInfo *cellInfo)
498 {
499     bool ret = false;
500     if (cellInfo == nullptr) {
501         TELEPHONY_LOGE("cellInfo is nullptr");
502         return ret;
503     }
504     sptr<NrCellInformation> cell = new NrCellInformation;
505     if (cell != nullptr && cellInfo != nullptr) {
506         int32_t &nrArfcn = cellInfo->ServiceCellParas.nr.nrArfcn;
507         int32_t &pci = cellInfo->ServiceCellParas.nr.pci;
508         int32_t &tac = cellInfo->ServiceCellParas.nr.tac;
509         int64_t &nci = cellInfo->ServiceCellParas.nr.nci;
510         int32_t &rsrp = cellInfo->ServiceCellParas.nr.rsrp;
511         int32_t &rsrq = cellInfo->ServiceCellParas.nr.rsrq;
512         rsrp = ZERO_VALUE - rsrp;
513         rsrq = ZERO_VALUE - rsrq;
514         cell->Init(0, 0, 0);
515         cell->SetNrParam(nrArfcn, pci, tac, nci);
516         cell->SetNrSignalParam(rsrp, rsrq);
517         cell->SetSignalIntensity(rsrp);
518         neighboringCellInfos_.emplace_back(cell);
519         TELEPHONY_LOGI("CellInfo::ProcessNeighboringCellNr arfcn:%{private}d pci:%{private}d slotId:%{public}d",
520             nrArfcn, pci, slotId_);
521         ret = true;
522     }
523     return ret;
524 }
525 
ProcessCurrentCellGsm(CurrentCellInformation * cellInfo)526 bool CellInfo::ProcessCurrentCellGsm(CurrentCellInformation *cellInfo)
527 {
528     bool ret = false;
529     if (cellInfo == nullptr) {
530         TELEPHONY_LOGE("cellInfo is nullptr");
531         return ret;
532     }
533     sptr<GsmCellInformation> cell = new GsmCellInformation;
534     if (cell != nullptr) {
535         int32_t &arfcn = cellInfo->ServiceCellParas.gsm.arfcn;
536         int32_t &cellId = cellInfo->ServiceCellParas.gsm.cellId;
537         int32_t &bsic = cellInfo->ServiceCellParas.gsm.bsic;
538         int32_t &lac = cellInfo->ServiceCellParas.gsm.lac;
539         int32_t &rxlev = cellInfo->ServiceCellParas.gsm.rxlev;
540         rxlev = ZERO_VALUE - rxlev;
541         cell->Init(cellInfo->mcc, cellInfo->mnc, cellId);
542         cell->SetGsmParam(bsic, lac, arfcn);
543         cell->SetSignalIntensity(rxlev);
544         cell->SetIsCamped(true);
545         int32_t level = GetCurrentSignalLevelGsm(rxlev);
546         cell->SetSignalLevel(level);
547         currentCellInfo_ = cell;
548         cellInfos_.emplace_back(cell);
549         TELEPHONY_LOGI(
550             "CellInfo::ProcessCurrentCellGsm arfcn:%{private}d cellId:%{private}d"
551             "bsic:%{private}d lac:%{private}d rxlev:%{public}d slotId:%{public}d",
552             arfcn, cellId, bsic, lac, rxlev, slotId_);
553         ret = true;
554     }
555     return ret;
556 }
557 
ProcessCurrentCellLte(CurrentCellInformation * cellInfo)558 bool CellInfo::ProcessCurrentCellLte(CurrentCellInformation *cellInfo)
559 {
560     bool ret = false;
561     if (cellInfo == nullptr) {
562         TELEPHONY_LOGE("cellInfo is nullptr");
563         return ret;
564     }
565     sptr<LteCellInformation> cell = new LteCellInformation;
566     if (cell != nullptr) {
567         int32_t &arfcn = cellInfo->ServiceCellParas.lte.arfcn;
568         int32_t &pci = cellInfo->ServiceCellParas.lte.pci;
569         int32_t &cellId = cellInfo->ServiceCellParas.lte.cellId;
570         int32_t &tac = cellInfo->ServiceCellParas.lte.tac;
571         int32_t &rsrp = cellInfo->ServiceCellParas.lte.rsrp;
572         rsrp = ZERO_VALUE - rsrp;
573         cell->Init(cellInfo->mcc, cellInfo->mnc, cellId);
574         cell->SetLteParam(pci, tac, arfcn);
575         cell->SetSignalIntensity(rsrp);
576         cell->SetIsCamped(true);
577         int32_t level = GetCurrentSignalLevelLte(rsrp);
578         cell->SetSignalLevel(level);
579         currentCellInfo_ = cell;
580         cellInfos_.emplace_back(cell);
581         TELEPHONY_LOGI(
582             "CellInfo::ProcessCurrentCellLte arfcn:%{private}d pci:%{private}d rsrp:%{public}d slotId:%{public}d",
583             arfcn, pci, rsrp, slotId_);
584         ret = true;
585     }
586     return ret;
587 }
588 
ProcessCurrentCellWcdma(CurrentCellInformation * cellInfo)589 bool CellInfo::ProcessCurrentCellWcdma(CurrentCellInformation *cellInfo)
590 {
591     bool ret = false;
592     if (cellInfo == nullptr) {
593         TELEPHONY_LOGE("cellInfo is nullptr");
594         return ret;
595     }
596     sptr<WcdmaCellInformation> cell = new WcdmaCellInformation;
597     if (cell != nullptr) {
598         int32_t &arfcn = cellInfo->ServiceCellParas.wcdma.arfcn;
599         int32_t &psc = cellInfo->ServiceCellParas.wcdma.psc;
600         int32_t &cellId = cellInfo->ServiceCellParas.wcdma.cellId;
601         int32_t &lac = cellInfo->ServiceCellParas.wcdma.lac;
602         int32_t &rscp = cellInfo->ServiceCellParas.wcdma.rscp;
603         rscp = ZERO_VALUE - rscp;
604         cell->Init(cellInfo->mcc, cellInfo->mnc, cellId);
605         cell->SetWcdmaParam(psc, lac, arfcn);
606         cell->SetSignalIntensity(rscp);
607         cell->SetIsCamped(true);
608         int32_t level = GetCurrentSignalLevelWcdma(rscp);
609         cell->SetSignalLevel(level);
610         currentCellInfo_ = cell;
611         cellInfos_.emplace_back(cell);
612         TELEPHONY_LOGI(
613             "CellInfo::ProcessCurrentCellWcdma arfcn:%{private}d psc:%{private}d rscp:%{public}d", arfcn, psc, rscp);
614         ret = true;
615     }
616     return ret;
617 }
618 
ProcessCurrentCellCdma(CurrentCellInformation * cellInfo)619 bool CellInfo::ProcessCurrentCellCdma(CurrentCellInformation *cellInfo)
620 {
621     bool ret = false;
622     if (cellInfo == nullptr) {
623         TELEPHONY_LOGE("cellInfo is nullptr");
624         return ret;
625     }
626     sptr<CdmaCellInformation> cell = new CdmaCellInformation;
627     if (cell != nullptr) {
628         int32_t &baseId = cellInfo->ServiceCellParas.cdma.baseId;
629         int32_t &longitude = cellInfo->ServiceCellParas.cdma.longitude;
630         int32_t &latitude = cellInfo->ServiceCellParas.cdma.latitude;
631         int32_t &networkId = cellInfo->ServiceCellParas.cdma.networkId;
632         int32_t &systemId = cellInfo->ServiceCellParas.cdma.systemId;
633         int32_t &pilotStrength = cellInfo->ServiceCellParas.cdma.pilotStrength;
634         pilotStrength = ZERO_VALUE - pilotStrength;
635         cell->Init(cellInfo->mcc, cellInfo->mnc, baseId);
636         cell->SetCdmaParam(baseId, latitude, longitude, networkId, systemId);
637         cell->SetSignalIntensity(pilotStrength);
638         cell->SetIsCamped(true);
639         int32_t level = GetCurrentSignalLevelCdma(pilotStrength);
640         cell->SetSignalLevel(level);
641         currentCellInfo_ = cell;
642         cellInfos_.emplace_back(cell);
643         TELEPHONY_LOGI(
644             "CellInfo::ProcessCurrentCellCdma baseId:%{private}d networkId:%{private}d pilotStrength:%{public}d",
645             baseId, networkId, pilotStrength);
646         ret = true;
647     }
648     return ret;
649 }
650 
ProcessCurrentCellTdscdma(CurrentCellInformation * cellInfo)651 bool CellInfo::ProcessCurrentCellTdscdma(CurrentCellInformation *cellInfo)
652 {
653     bool ret = false;
654     if (cellInfo == nullptr) {
655         TELEPHONY_LOGE("cellInfo is nullptr");
656         return ret;
657     }
658     sptr<TdscdmaCellInformation> cell = new TdscdmaCellInformation;
659     if (cell != nullptr) {
660         int32_t &arfcn = cellInfo->ServiceCellParas.tdscdma.arfcn;
661         int32_t &cpid = cellInfo->ServiceCellParas.tdscdma.cpid;
662         int32_t &cellId = cellInfo->ServiceCellParas.tdscdma.cellId;
663         int32_t &lac = cellInfo->ServiceCellParas.tdscdma.lac;
664         int32_t &rscp = cellInfo->ServiceCellParas.tdscdma.rscp;
665         rscp = ZERO_VALUE - rscp;
666         cell->Init(cellInfo->mcc, cellInfo->mnc, cellId);
667         cell->SetTdscdmaParam(cpid, lac, arfcn);
668         cell->SetSignalIntensity(rscp);
669         cell->SetIsCamped(true);
670         int32_t level = GetCurrentSignalLevelTdscdma(rscp);
671         cell->SetSignalLevel(level);
672         currentCellInfo_ = cell;
673         cellInfos_.emplace_back(cell);
674         TELEPHONY_LOGI("CellInfo::ProcessCurrentCellTdscdma arfcn:%{private}d pci:%{private}d slotId:%{public}d", arfcn,
675             cpid, slotId_);
676         ret = true;
677     }
678     return ret;
679 }
680 
ProcessCurrentCellNr(CurrentCellInformation * cellInfo)681 bool CellInfo::ProcessCurrentCellNr(CurrentCellInformation *cellInfo)
682 {
683     bool ret = false;
684     if (cellInfo == nullptr) {
685         TELEPHONY_LOGE("cellInfo is nullptr");
686         return ret;
687     }
688     sptr<NrCellInformation> cell = new NrCellInformation;
689     if (cell != nullptr && cellInfo != nullptr) {
690         int32_t &nrArfcn = cellInfo->ServiceCellParas.nr.nrArfcn;
691         int32_t &pci = cellInfo->ServiceCellParas.nr.pci;
692         int32_t &tac = cellInfo->ServiceCellParas.nr.tac;
693         int64_t &nci = cellInfo->ServiceCellParas.nr.nci;
694         int32_t &rsrp = cellInfo->ServiceCellParas.nr.rsrp;
695         int32_t &rsrq = cellInfo->ServiceCellParas.nr.rsrq;
696         rsrp = ZERO_VALUE - rsrp;
697         rsrq = ZERO_VALUE - rsrq;
698         cell->Init(cellInfo->mcc, cellInfo->mnc, 0);
699         cell->SetNrParam(nrArfcn, pci, tac, nci);
700         cell->SetNrSignalParam(rsrp, rsrq);
701         cell->SetSignalIntensity(rsrp);
702         cell->SetIsCamped(true);
703         int32_t level = GetCurrentSignalLevelNr(rsrp);
704         cell->SetSignalLevel(level);
705         currentCellInfo_ = cell;
706         cellInfos_.emplace_back(cell);
707 
708         TELEPHONY_LOGI(
709             "CellInfo::ProcessCurrentCellNr arfcn:%{private}d pci:%{private}d slotId:%{public}d rsrp:%{public}d "
710             "rsrq:%{public}d", nrArfcn, pci, slotId_, rsrp, rsrq);
711         ret = true;
712     }
713     return ret;
714 }
715 
GetCurrentSignalLevelGsm(int32_t rxlev)716 int32_t CellInfo::GetCurrentSignalLevelGsm(int32_t rxlev)
717 {
718     int32_t level = SIGNAL_LEVEL_INVALID;
719     if (rxlev >= SIGNAL_RSSI_MAXIMUM) {
720         TELEPHONY_LOGE("CellInfo::GetCurrentSignalLevelGsm Value is Invalid.");
721         return level;
722     }
723     for (int32_t i = signalBar_; i >= 0; --i) {
724         if (rxlev >= GSM_SIGNAL_THRESHOLD[i]) {
725             level = i;
726             break;
727         }
728     }
729     return level;
730 }
731 
GetCurrentSignalLevelLte(int32_t rsrp)732 int32_t CellInfo::GetCurrentSignalLevelLte(int32_t rsrp)
733 {
734     int32_t level = SIGNAL_LEVEL_INVALID;
735     if (rsrp >= SIGNAL_RSSI_MAXIMUM) {
736         TELEPHONY_LOGE("CellInfo::GetCurrentSignalLevelLte Value is Invalid.");
737         return level;
738     }
739     for (int32_t i = signalBar_; i >= 0; --i) {
740         if (rsrp >= LTE_SIGNAL_THRESHOLD[i]) {
741             level = i;
742             break;
743         }
744     }
745     return level;
746 }
747 
GetCurrentSignalLevelWcdma(int32_t rscp)748 int32_t CellInfo::GetCurrentSignalLevelWcdma(int32_t rscp)
749 {
750     int32_t level = SIGNAL_LEVEL_INVALID;
751     if (rscp >= SIGNAL_RSSI_MAXIMUM) {
752         TELEPHONY_LOGE("CellInfo::GetCurrentSignalLevelWcdma Value is Invalid.");
753         return level;
754     }
755     for (int32_t i = signalBar_; i >= 0; --i) {
756         if (rscp >= WCDMA_SIGNAL_THRESHOLD[i]) {
757             level = i;
758             break;
759         }
760     }
761     return level;
762 }
763 
GetCurrentSignalLevelCdma(int32_t pilotStrength)764 int32_t CellInfo::GetCurrentSignalLevelCdma(int32_t pilotStrength)
765 {
766     int32_t level = SIGNAL_LEVEL_INVALID;
767     if (pilotStrength >= SIGNAL_RSSI_MAXIMUM) {
768         TELEPHONY_LOGE("CellInfo::GetCurrentSignalLevelCdma Value is Invalid.");
769         return level;
770     }
771     for (int32_t i = signalBar_; i >= 0; --i) {
772         if (pilotStrength >= CDMA_SIGNAL_THRESHOLD[i]) {
773             level = i;
774             break;
775         }
776     }
777     return level;
778 }
779 
GetCurrentSignalLevelTdscdma(int32_t rscp)780 int32_t CellInfo::GetCurrentSignalLevelTdscdma(int32_t rscp)
781 {
782     int32_t level = SIGNAL_LEVEL_INVALID;
783     if (rscp >= SIGNAL_RSSI_MAXIMUM) {
784         TELEPHONY_LOGE("CellInfo::GetCurrentSignalLevelTdscdma Value is Invalid.");
785         return level;
786     }
787     for (int32_t i = signalBar_; i >= 0; --i) {
788         if (rscp >= TD_SCDMA_SIGNAL_THRESHOLD[i]) {
789             level = i;
790             break;
791         }
792     }
793     return level;
794 }
795 
GetCurrentSignalLevelNr(int32_t rsrp)796 int32_t CellInfo::GetCurrentSignalLevelNr(int32_t rsrp)
797 {
798     int32_t level = SIGNAL_LEVEL_INVALID;
799     if (rsrp >= SIGNAL_RSSI_MAXIMUM) {
800         TELEPHONY_LOGE("CellInfo::GetCurrentSignalLevelNr Value is Invalid.");
801         return level;
802     }
803     for (int32_t i = signalBar_; i >= 0; --i) {
804         if (rsrp >= NR_SIGNAL_THRESHOLD[i]) {
805             level = i;
806             break;
807         }
808     }
809     return level;
810 }
811 
GetCellInfoList(std::vector<sptr<CellInformation>> & cellInfo)812 void CellInfo::GetCellInfoList(std::vector<sptr<CellInformation>> &cellInfo)
813 {
814     cellInfo.clear();
815     {
816         std::lock_guard<ffrt::mutex> lock(mutex_);
817         for (auto &cell : cellInfos_) {
818             AddCellInformation(cell, cellInfo);
819         }
820     }
821     TELEPHONY_LOGD("CellInfo::GetCellInfoList size:%{public}zu slotId:%{public}d", cellInfo.size(), slotId_);
822 }
823 
GetNeighboringCellInfoList(std::vector<sptr<CellInformation>> & cellInfo)824 void CellInfo::GetNeighboringCellInfoList(std::vector<sptr<CellInformation>> &cellInfo)
825 {
826     cellInfo.clear();
827     {
828         std::lock_guard<ffrt::mutex> lock(mutex_);
829         for (auto &cell : neighboringCellInfos_) {
830             AddCellInformation(cell, cellInfo);
831         }
832     }
833     TELEPHONY_LOGD("CellInfo::GetCellInfGetNeighboringCellInfoListoList size:%{public}zu slotId:%{public}d",
834         cellInfo.size(), slotId_);
835 }
836 
ClearCellInfoList()837 void CellInfo::ClearCellInfoList()
838 {
839     std::lock_guard<ffrt::mutex> lock(mutex_);
840     currentCellInfo_ = nullptr;
841     cellInfos_.clear();
842 }
843 
AddCellInformation(sptr<CellInformation> & cellInfo,std::vector<sptr<CellInformation>> & cellInfos)844 void CellInfo::AddCellInformation(sptr<CellInformation> &cellInfo, std::vector<sptr<CellInformation>> &cellInfos)
845 {
846     CellInformation::CellType type = cellInfo->GetNetworkType();
847     switch (type) {
848         case CellInformation::CellType::CELL_TYPE_GSM: {
849             sptr<GsmCellInformation> cell = new GsmCellInformation;
850             GsmCellInformation &gsmCell = *cell;
851             gsmCell = *(static_cast<GsmCellInformation *>(cellInfo.GetRefPtr()));
852             cellInfos.emplace_back(cell);
853             break;
854         }
855         case CellInformation::CellType::CELL_TYPE_LTE: {
856             sptr<LteCellInformation> cell = new LteCellInformation;
857             LteCellInformation &lteCell = *cell;
858             lteCell = *(static_cast<LteCellInformation *>(cellInfo.GetRefPtr()));
859             cellInfos.emplace_back(cell);
860             break;
861         }
862         case CellInformation::CellType::CELL_TYPE_WCDMA: {
863             sptr<WcdmaCellInformation> cell = new WcdmaCellInformation;
864             WcdmaCellInformation &wcdmaCell = *cell;
865             wcdmaCell = *(static_cast<WcdmaCellInformation *>(cellInfo.GetRefPtr()));
866             cellInfos.emplace_back(cell);
867             break;
868         }
869         case CellInformation::CellType::CELL_TYPE_CDMA: {
870             sptr<CdmaCellInformation> cell = new CdmaCellInformation;
871             CdmaCellInformation &cdmaCell = *cell;
872             cdmaCell = *(static_cast<CdmaCellInformation *>(cellInfo.GetRefPtr()));
873             cellInfos.emplace_back(cell);
874             break;
875         }
876         case CellInformation::CellType::CELL_TYPE_TDSCDMA: {
877             sptr<TdscdmaCellInformation> cell = new TdscdmaCellInformation;
878             TdscdmaCellInformation &tdscdmaCell = *cell;
879             tdscdmaCell = *(static_cast<TdscdmaCellInformation *>(cellInfo.GetRefPtr()));
880             cellInfos.emplace_back(cell);
881             break;
882         }
883         case CellInformation::CellType::CELL_TYPE_NR: {
884             sptr<NrCellInformation> cell = new NrCellInformation;
885             NrCellInformation &nrCell = *cell;
886             nrCell = *(static_cast<NrCellInformation *>(cellInfo.GetRefPtr()));
887             cellInfos.emplace_back(cell);
888             break;
889         }
890         default:
891             break;
892     }
893 }
894 
GetCellLocation()895 sptr<CellLocation> CellInfo::GetCellLocation()
896 {
897     std::lock_guard<ffrt::mutex> lock(mutex_);
898     if (currentCellInfo_ == nullptr) {
899         TELEPHONY_LOGE("CellInfo::GetCellLocation is null slotId:%{public}d", slotId_);
900         return nullptr;
901     }
902     CellInformation::CellType type = currentCellInfo_->GetNetworkType();
903     switch (type) {
904         case CellInformation::CellType::CELL_TYPE_GSM: {
905             sptr<GsmCellInformation> cellinfo =
906                 static_cast<GsmCellInformation *>(currentCellInfo_.GetRefPtr());
907             sptr<GsmCellLocation> cellLocation = new GsmCellLocation;
908             cellLocation->SetGsmParam(cellinfo->GetCellId(), cellinfo->GetLac());
909             return cellLocation;
910         }
911         case CellInformation::CellType::CELL_TYPE_TDSCDMA: {
912             sptr<GsmCellInformation> cellinfo = static_cast<GsmCellInformation *>(currentCellInfo_.GetRefPtr());
913             sptr<GsmCellLocation> cellLocation = new GsmCellLocation;
914             cellLocation->SetGsmParam(cellinfo->GetCellId(), cellinfo->GetLac());
915             return cellLocation;
916         }
917         case CellInformation::CellType::CELL_TYPE_WCDMA: {
918             sptr<WcdmaCellInformation> cellinfo = static_cast<WcdmaCellInformation *>(currentCellInfo_.GetRefPtr());
919             sptr<GsmCellLocation> cellLocation = new GsmCellLocation;
920             cellLocation->SetGsmParam(cellinfo->GetCellId(), cellinfo->GetLac(), cellinfo->GetPsc());
921             return cellLocation;
922         }
923         case CellInformation::CellType::CELL_TYPE_CDMA: {
924             sptr<CdmaCellInformation> cellinfo = static_cast<CdmaCellInformation *>(currentCellInfo_.GetRefPtr());
925             sptr<CdmaCellLocation> cellLocation = new CdmaCellLocation;
926             cellLocation->SetCdmaParam(cellinfo->GetBaseId(), cellinfo->GetLatitude(), cellinfo->GetLongitude(),
927                 cellinfo->GetNid(), cellinfo->GetSid());
928             return cellLocation;
929         }
930         case CellInformation::CellType::CELL_TYPE_LTE:
931         case CellInformation::CellType::CELL_TYPE_NR:
932             return GetCellLocationExt(type);
933         default:
934             TELEPHONY_LOGE("CellInfo::GetCellLocation cell type error slotId:%{public}d", slotId_);
935             break;
936     }
937     return nullptr;
938 }
939 
GetCellLocationExt(CellInformation::CellType type)940 sptr<CellLocation> CellInfo::GetCellLocationExt(CellInformation::CellType type)
941 {
942     if (currentCellInfo_ == nullptr) {
943         TELEPHONY_LOGE("CellInfo::GetCellLocationExt is null slotId:%{public}d", slotId_);
944         return nullptr;
945     }
946     if (type == CellInformation::CellType::CELL_TYPE_LTE) {
947         sptr<LteCellInformation> cellinfo = static_cast<LteCellInformation *>(currentCellInfo_.GetRefPtr());
948         sptr<GsmCellLocation> cellLocation = new GsmCellLocation;
949         cellLocation->SetGsmParam(cellinfo->GetCellId(), cellinfo->GetTac());
950         return cellLocation;
951     } else if (type == CellInformation::CellType::CELL_TYPE_NR) {
952         sptr<NrCellInformation> cellinfo = static_cast<NrCellInformation *>(currentCellInfo_.GetRefPtr());
953         sptr<GsmCellLocation> cellLocation = new GsmCellLocation;
954         cellLocation->SetGsmParam(cellinfo->GetCellId(), cellinfo->GetTac());
955         return cellLocation;
956     }
957     return nullptr;
958 }
959 } // namespace Telephony
960 } // namespace OHOS