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