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