• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "cell_information.h"
17 
18 #include <cstdint>
19 #include <memory>
20 #include <securec.h>
21 
22 #include "iosfwd"
23 #include "new"
24 #include "parcel.h"
25 #include "string"
26 #include "ctime"
27 
28 namespace OHOS {
29 namespace Telephony {
30 const int32_t MNC_INT_MAX = 999;
31 const int32_t MNC_DIGIT_OFFSET = 28;
32 const uint32_t MNC_VALID_BIT = 0X0FFFFFFF;
Init(int32_t mcc,int32_t mnc,int32_t cellId)33 void CellInformation::Init(int32_t mcc, int32_t mnc, int32_t cellId)
34 {
35     if (mnc > MNC_INT_MAX) {
36         int mnc_digit = mnc >> MNC_DIGIT_OFFSET;
37         mnc = static_cast<int32_t>(static_cast<uint32_t>(mnc) & MNC_VALID_BIT);
38         char mnc_str[MNC_DIGIT_OFFSET] = {0};
39         char strFormat[MNC_DIGIT_OFFSET] = {0};
40         int size = snprintf_s(strFormat, MNC_DIGIT_OFFSET, MNC_DIGIT_OFFSET - 1, "%s%dd", "%0", mnc_digit);
41         if (size > 0) {
42             size = snprintf_s(mnc_str, mnc_digit + 1, mnc_digit, strFormat, mnc);
43         }
44         if (size > 0) {
45             mnc_ = mnc_str;
46         }
47     } else {
48         mnc_ = std::to_string(mnc);
49     }
50     mcc_ = std::to_string(mcc);
51     cellId_ = cellId;
52     timeStamp_ = static_cast<uint64_t>(time(0));
53 }
54 
GetCellId() const55 int32_t CellInformation::GetCellId() const
56 {
57     return cellId_;
58 }
59 
GetMcc() const60 std::string CellInformation::GetMcc() const
61 {
62     return mcc_;
63 }
64 
GetMnc() const65 std::string CellInformation::GetMnc() const
66 {
67     return mnc_;
68 }
69 
GetTimeStamp() const70 uint64_t CellInformation::GetTimeStamp() const
71 {
72     return timeStamp_;
73 }
74 
GetSignalIntensity() const75 int32_t CellInformation::GetSignalIntensity() const
76 {
77     return signalIntensity_;
78 }
79 
SetSignalIntensity(int32_t signalIntensity)80 void CellInformation::SetSignalIntensity(int32_t signalIntensity)
81 {
82     signalIntensity_ = signalIntensity;
83     timeStamp_ = static_cast<uint64_t>(time(0));
84 }
85 
GetSignalLevel() const86 int32_t CellInformation::GetSignalLevel() const
87 {
88     return signalLevel_;
89 }
90 
SetSignalLevel(int32_t signalLevel)91 void CellInformation::SetSignalLevel(int32_t signalLevel)
92 {
93     signalLevel_ = signalLevel;
94     timeStamp_ = static_cast<uint64_t>(time(0));
95 }
96 
GetIsCamped() const97 bool CellInformation::GetIsCamped() const
98 {
99     return isCamped_;
100 }
101 
SetIsCamped(bool isCamped)102 void CellInformation::SetIsCamped(bool isCamped)
103 {
104     isCamped_ = isCamped;
105     timeStamp_ = static_cast<uint64_t>(time(0));
106 }
107 
Unmarshalling(Parcel & parcel)108 CellInformation *CellInformation::Unmarshalling(Parcel &parcel)
109 {
110     return nullptr;
111 }
112 
SetGsmParam(int32_t bsic,int32_t lac,int32_t arfcn)113 void GsmCellInformation::SetGsmParam(int32_t bsic, int32_t lac, int32_t arfcn)
114 {
115     bsic_ = bsic;
116     lac_ = lac;
117     arfcn_ = arfcn;
118 }
119 
GsmCellInformation(const GsmCellInformation & gsmCell)120 GsmCellInformation::GsmCellInformation(const GsmCellInformation &gsmCell)
121 {
122     mcc_ = gsmCell.mcc_;
123     mnc_ = gsmCell.mnc_;
124     arfcn_ = gsmCell.arfcn_;
125     cellId_ = gsmCell.cellId_;
126     bsic_ = gsmCell.bsic_;
127     lac_ = gsmCell.lac_;
128     timeStamp_ = gsmCell.timeStamp_;
129     signalLevel_ = gsmCell.signalLevel_;
130     signalIntensity_ = gsmCell.signalIntensity_;
131     isCamped_ = gsmCell.isCamped_;
132 }
133 
operator =(const GsmCellInformation & gsmCell)134 GsmCellInformation &GsmCellInformation::operator=(const GsmCellInformation &gsmCell)
135 {
136     mcc_ = gsmCell.mcc_;
137     mnc_ = gsmCell.mnc_;
138     arfcn_ = gsmCell.arfcn_;
139     cellId_ = gsmCell.cellId_;
140     bsic_ = gsmCell.bsic_;
141     lac_ = gsmCell.lac_;
142     timeStamp_ = gsmCell.timeStamp_;
143     signalLevel_ = gsmCell.signalLevel_;
144     signalIntensity_ = gsmCell.signalIntensity_;
145     isCamped_ = gsmCell.isCamped_;
146     return *this;
147 }
148 
operator ==(const GsmCellInformation & other) const149 bool GsmCellInformation::operator==(const GsmCellInformation &other) const
150 {
151     return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
152         arfcn_ == other.arfcn_ && cellId_ == other.cellId_ &&
153         bsic_ == other.bsic_ && lac_ == other.lac_ &&
154         signalLevel_ == other.signalLevel_ &&
155         signalIntensity_ == other.signalIntensity_ &&
156         isCamped_ == other.isCamped_;
157 }
158 
GetNetworkType() const159 CellInformation::CellType GsmCellInformation::GetNetworkType() const
160 {
161     return CellType::CELL_TYPE_GSM;
162 }
163 
GetArfcn() const164 int32_t GsmCellInformation::GetArfcn() const
165 {
166     return arfcn_;
167 }
168 
ToString() const169 std::string GsmCellInformation::ToString() const
170 {
171     int32_t netWorkType = static_cast<int32_t>(GsmCellInformation::GetNetworkType());
172     std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
173         ",mnc:" + mnc_ + ",arfcn:" + std::to_string(arfcn_) + ",cellId:" + std::to_string(cellId_) +
174         ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
175         ",signalIntensity_:" + std::to_string(signalIntensity_) + ",bsic:" + std::to_string(bsic_) +
176         ",lac:" + std::to_string(lac_));
177     return content;
178 }
179 
Marshalling(Parcel & parcel) const180 bool GsmCellInformation::Marshalling(Parcel &parcel) const
181 {
182     if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_GSM))) {
183         return false;
184     }
185     if (!parcel.WriteString(mcc_)) {
186         return false;
187     }
188     if (!parcel.WriteString(mnc_)) {
189         return false;
190     }
191     if (!parcel.WriteInt32(arfcn_)) {
192         return false;
193     }
194     if (!parcel.WriteInt32(cellId_)) {
195         return false;
196     }
197     if (!parcel.WriteInt32(bsic_)) {
198         return false;
199     }
200     if (!parcel.WriteInt32(lac_)) {
201         return false;
202     }
203     if (!parcel.WriteUint64(timeStamp_)) {
204         return false;
205     }
206     if (!parcel.WriteInt32(signalLevel_)) {
207         return false;
208     }
209     if (!parcel.WriteInt32(signalIntensity_)) {
210         return false;
211     }
212     if (!parcel.WriteBool(isCamped_)) {
213         return false;
214     }
215     return true;
216 }
217 
Unmarshalling(Parcel & parcel)218 GsmCellInformation *GsmCellInformation::Unmarshalling(Parcel &parcel)
219 {
220     GsmCellInformation *param = new (std::nothrow) GsmCellInformation();
221     if (param == nullptr) {
222         return nullptr;
223     }
224     if (!param->ReadFromParcel(parcel)) {
225         delete param;
226         param = nullptr;
227     }
228     return param;
229 }
230 
ReadFromParcel(Parcel & parcel)231 bool GsmCellInformation::ReadFromParcel(Parcel &parcel)
232 {
233     mcc_ = parcel.ReadString();
234     mnc_ = parcel.ReadString();
235     arfcn_ = parcel.ReadInt32();
236     cellId_ = parcel.ReadInt32();
237     bsic_ = parcel.ReadInt32();
238     lac_ = parcel.ReadInt32();
239     timeStamp_ = parcel.ReadUint64();
240     signalLevel_ = parcel.ReadInt32();
241     signalIntensity_ = parcel.ReadInt32();
242     isCamped_ = parcel.ReadBool();
243 
244     return true;
245 }
246 
GetLac() const247 int32_t GsmCellInformation::GetLac() const
248 {
249     return lac_;
250 }
251 
GetBsic() const252 int32_t GsmCellInformation::GetBsic() const
253 {
254     return bsic_;
255 }
256 
UpdateLocation(int32_t cellId,int32_t lac)257 void GsmCellInformation::UpdateLocation(int32_t cellId, int32_t lac)
258 {
259     cellId_ = cellId;
260     lac_ = lac;
261     timeStamp_ = time(0);
262 }
263 
SetLteParam(int32_t pci,int32_t tac,int32_t arfcn)264 void LteCellInformation::SetLteParam(int32_t pci, int32_t tac, int32_t arfcn)
265 {
266     pci_ = pci;
267     tac_ = tac;
268     earfcn_ = arfcn;
269 }
270 
LteCellInformation(const LteCellInformation & lteCell)271 LteCellInformation::LteCellInformation(const LteCellInformation &lteCell)
272 {
273     mcc_ = lteCell.mcc_;
274     mnc_ = lteCell.mnc_;
275     earfcn_ = lteCell.earfcn_;
276     cellId_ = lteCell.cellId_;
277     pci_ = lteCell.pci_;
278     tac_ = lteCell.tac_;
279     timeStamp_ = lteCell.timeStamp_;
280     signalLevel_ = lteCell.signalLevel_;
281     signalIntensity_ = lteCell.signalIntensity_;
282     isCamped_ = lteCell.isCamped_;
283 }
284 
operator =(const LteCellInformation & lteCell)285 LteCellInformation &LteCellInformation::operator=(const LteCellInformation &lteCell)
286 {
287     mcc_ = lteCell.mcc_;
288     mnc_ = lteCell.mnc_;
289     earfcn_ = lteCell.earfcn_;
290     cellId_ = lteCell.cellId_;
291     pci_ = lteCell.pci_;
292     tac_ = lteCell.tac_;
293     timeStamp_ = lteCell.timeStamp_;
294     signalLevel_ = lteCell.signalLevel_;
295     signalIntensity_ = lteCell.signalIntensity_;
296     isCamped_ = lteCell.isCamped_;
297     return *this;
298 }
299 
operator ==(const LteCellInformation & other) const300 bool LteCellInformation::operator==(const LteCellInformation &other) const
301 {
302     return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
303         earfcn_ == other.earfcn_ && cellId_ == other.cellId_ &&
304         pci_ == other.pci_ && tac_ == other.tac_ &&
305         signalLevel_ == other.signalLevel_ && signalIntensity_ == other.signalIntensity_ &&
306         isCamped_ == other.isCamped_;
307 }
308 
GetNetworkType() const309 CellInformation::CellType LteCellInformation::GetNetworkType() const
310 {
311     return CellType::CELL_TYPE_LTE;
312 }
313 
GetArfcn() const314 int32_t LteCellInformation::GetArfcn() const
315 {
316     return earfcn_;
317 }
318 
Marshalling(Parcel & parcel) const319 bool LteCellInformation::Marshalling(Parcel &parcel) const
320 {
321     if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_LTE))) {
322         return false;
323     }
324     if (!parcel.WriteString(mcc_)) {
325         return false;
326     }
327     if (!parcel.WriteString(mnc_)) {
328         return false;
329     }
330     if (!parcel.WriteInt32(earfcn_)) {
331         return false;
332     }
333     if (!parcel.WriteInt32(cellId_)) {
334         return false;
335     }
336     if (!parcel.WriteInt32(pci_)) {
337         return false;
338     }
339     if (!parcel.WriteInt32(tac_)) {
340         return false;
341     }
342     if (!parcel.WriteInt64(timeStamp_)) {
343         return false;
344     }
345     if (!parcel.WriteInt32(signalLevel_)) {
346         return false;
347     }
348     if (!parcel.WriteInt32(signalIntensity_)) {
349         return false;
350     }
351     if (!parcel.WriteBool(isCamped_)) {
352         return false;
353     }
354     return true;
355 }
356 
Unmarshalling(Parcel & parcel)357 LteCellInformation *LteCellInformation::Unmarshalling(Parcel &parcel)
358 {
359     LteCellInformation *param = new (std::nothrow) LteCellInformation();
360     if (param == nullptr) {
361         return nullptr;
362     }
363     if (!param->ReadFromParcel(parcel)) {
364         delete param;
365         param = nullptr;
366     }
367     return param;
368 }
369 
ReadFromParcel(Parcel & parcel)370 bool LteCellInformation::ReadFromParcel(Parcel &parcel)
371 {
372     mcc_ = parcel.ReadString();
373     mnc_ = parcel.ReadString();
374     earfcn_ = parcel.ReadInt32();
375     cellId_ = parcel.ReadInt32();
376     pci_ = parcel.ReadInt32();
377     tac_ = parcel.ReadInt32();
378     timeStamp_ = parcel.ReadInt64();
379     signalLevel_ = parcel.ReadInt32();
380     signalIntensity_ = parcel.ReadInt32();
381     isCamped_ = parcel.ReadBool();
382     return true;
383 }
384 
GetPci() const385 int32_t LteCellInformation::GetPci() const
386 {
387     return pci_;
388 }
389 
GetTac() const390 int32_t LteCellInformation::GetTac() const
391 {
392     return tac_;
393 }
394 
UpdateLocation(int32_t cellId,int32_t tac)395 void LteCellInformation::UpdateLocation(int32_t cellId, int32_t tac)
396 {
397     cellId_ = cellId;
398     tac_ = tac;
399     timeStamp_ = static_cast<uint64_t>(time(0));
400 }
401 
ToString() const402 std::string LteCellInformation::ToString() const
403 {
404     int32_t netWorkType = static_cast<int32_t>(LteCellInformation::GetNetworkType());
405     std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
406         ",mnc:" + mnc_ + ",earfcn:" + std::to_string(earfcn_) + ",cellId:" + std::to_string(cellId_) +
407         ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
408         ",signalIntensity:" + std::to_string(signalIntensity_) + ",pci:" + std::to_string(pci_) +
409         ",pci:" + std::to_string(pci_) + ",tac:" + std::to_string(tac_));
410     return content;
411 }
412 
SetWcdmaParam(int32_t psc,int32_t lac,int32_t arfcn)413 void WcdmaCellInformation::SetWcdmaParam(int32_t psc, int32_t lac, int32_t arfcn)
414 {
415     psc_ = psc;
416     lac_ = lac;
417     uarfcn_ = arfcn;
418 }
419 
WcdmaCellInformation(const WcdmaCellInformation & wcdmaCell)420 WcdmaCellInformation::WcdmaCellInformation(const WcdmaCellInformation &wcdmaCell)
421 {
422     mcc_ = wcdmaCell.mcc_;
423     mnc_ = wcdmaCell.mnc_;
424     uarfcn_ = wcdmaCell.uarfcn_;
425     cellId_ = wcdmaCell.cellId_;
426     psc_ = wcdmaCell.psc_;
427     lac_ = wcdmaCell.lac_;
428     timeStamp_ = wcdmaCell.timeStamp_;
429     signalLevel_ = wcdmaCell.signalLevel_;
430     signalIntensity_ = wcdmaCell.signalIntensity_;
431     isCamped_ = wcdmaCell.isCamped_;
432 }
433 
operator =(const WcdmaCellInformation & wcdmaCell)434 WcdmaCellInformation &WcdmaCellInformation::operator=(const WcdmaCellInformation &wcdmaCell)
435 {
436     mcc_ = wcdmaCell.mcc_;
437     mnc_ = wcdmaCell.mnc_;
438     uarfcn_ = wcdmaCell.uarfcn_;
439     cellId_ = wcdmaCell.cellId_;
440     psc_ = wcdmaCell.psc_;
441     lac_ = wcdmaCell.lac_;
442     timeStamp_ = wcdmaCell.timeStamp_;
443     signalLevel_ = wcdmaCell.signalLevel_;
444     signalIntensity_ = wcdmaCell.signalIntensity_;
445     isCamped_ = wcdmaCell.isCamped_;
446     return *this;
447 }
448 
operator ==(const WcdmaCellInformation & other) const449 bool WcdmaCellInformation::operator==(const WcdmaCellInformation &other) const
450 {
451     return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
452         uarfcn_ == other.uarfcn_ && cellId_ == other.cellId_ &&
453         psc_ == other.psc_ && lac_ == other.lac_ &&
454         signalLevel_ == other.signalLevel_ && signalIntensity_ == other.signalIntensity_ &&
455         isCamped_ == other.isCamped_;
456 }
457 
GetNetworkType() const458 CellInformation::CellType WcdmaCellInformation::GetNetworkType() const
459 {
460     return CellType::CELL_TYPE_WCDMA;
461 }
462 
GetArfcn() const463 int32_t WcdmaCellInformation::GetArfcn() const
464 {
465     return uarfcn_;
466 }
467 
Marshalling(Parcel & parcel) const468 bool WcdmaCellInformation::Marshalling(Parcel &parcel) const
469 {
470     if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_WCDMA))) {
471         return false;
472     }
473     if (!parcel.WriteString(mcc_)) {
474         return false;
475     }
476     if (!parcel.WriteString(mnc_)) {
477         return false;
478     }
479     if (!parcel.WriteInt32(uarfcn_)) {
480         return false;
481     }
482     if (!parcel.WriteInt32(cellId_)) {
483         return false;
484     }
485     if (!parcel.WriteInt32(psc_)) {
486         return false;
487     }
488     if (!parcel.WriteInt32(lac_)) {
489         return false;
490     }
491     if (!parcel.WriteInt64(timeStamp_)) {
492         return false;
493     }
494     if (!parcel.WriteInt32(signalLevel_)) {
495         return false;
496     }
497     if (!parcel.WriteInt32(signalIntensity_)) {
498         return false;
499     }
500     if (!parcel.WriteBool(isCamped_)) {
501         return false;
502     }
503     return true;
504 }
505 
Unmarshalling(Parcel & parcel)506 WcdmaCellInformation *WcdmaCellInformation::Unmarshalling(Parcel &parcel)
507 {
508     WcdmaCellInformation *param = new (std::nothrow) WcdmaCellInformation();
509     if (param == nullptr) {
510         return nullptr;
511     }
512     if (!param->ReadFromParcel(parcel)) {
513         delete param;
514         param = nullptr;
515     }
516     return param;
517 }
518 
ReadFromParcel(Parcel & parcel)519 bool WcdmaCellInformation::ReadFromParcel(Parcel &parcel)
520 {
521     mcc_ = parcel.ReadString();
522     mnc_ = parcel.ReadString();
523     uarfcn_ = parcel.ReadInt32();
524     cellId_ = parcel.ReadInt32();
525     psc_ = parcel.ReadInt32();
526     lac_ = parcel.ReadInt32();
527     timeStamp_ = parcel.ReadInt64();
528     signalLevel_ = parcel.ReadInt32();
529     signalIntensity_ = parcel.ReadInt32();
530     isCamped_ = parcel.ReadBool();
531     return true;
532 }
533 
GetPsc() const534 int32_t WcdmaCellInformation::GetPsc() const
535 {
536     return psc_;
537 }
538 
GetLac() const539 int32_t WcdmaCellInformation::GetLac() const
540 {
541     return lac_;
542 }
543 
UpdateLocation(int32_t cellId,int32_t lac)544 void WcdmaCellInformation::UpdateLocation(int32_t cellId, int32_t lac)
545 {
546     cellId_ = cellId;
547     lac_ = lac;
548     timeStamp_ = time(0);
549 }
550 
ToString() const551 std::string WcdmaCellInformation::ToString() const
552 {
553     int32_t netWorkType = static_cast<int32_t>(WcdmaCellInformation::GetNetworkType());
554     std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
555         ",mnc:" + mnc_ + ",uarfcn:" + std::to_string(uarfcn_) + ",cellId:" + std::to_string(cellId_) +
556         ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
557         ",signalIntensity:" + std::to_string(signalIntensity_) + ",psc:" + std::to_string(psc_) +
558         ",lac:" + std::to_string(lac_));
559     return content;
560 }
561 
SetTdscdmaParam(int32_t cpid,int32_t lac,int32_t arfcn)562 void TdscdmaCellInformation::SetTdscdmaParam(int32_t cpid, int32_t lac, int32_t arfcn)
563 {
564     cpid_ = cpid;
565     lac_ = lac;
566     uarfcn_ = arfcn;
567 }
568 
TdscdmaCellInformation(const TdscdmaCellInformation & tdscdmaCell)569 TdscdmaCellInformation::TdscdmaCellInformation(const TdscdmaCellInformation &tdscdmaCell)
570 {
571     mcc_ = tdscdmaCell.mcc_;
572     mnc_ = tdscdmaCell.mnc_;
573     uarfcn_ = tdscdmaCell.uarfcn_;
574     cellId_ = tdscdmaCell.cellId_;
575     cpid_ = tdscdmaCell.cpid_;
576     lac_ = tdscdmaCell.lac_;
577     timeStamp_ = tdscdmaCell.timeStamp_;
578     signalLevel_ = tdscdmaCell.signalLevel_;
579     signalIntensity_ = tdscdmaCell.signalIntensity_;
580     isCamped_ = tdscdmaCell.isCamped_;
581 }
582 
operator =(const TdscdmaCellInformation & tdscdmaCell)583 TdscdmaCellInformation &TdscdmaCellInformation::operator=(const TdscdmaCellInformation &tdscdmaCell)
584 {
585     mcc_ = tdscdmaCell.mcc_;
586     mnc_ = tdscdmaCell.mnc_;
587     uarfcn_ = tdscdmaCell.uarfcn_;
588     cellId_ = tdscdmaCell.cellId_;
589     cpid_ = tdscdmaCell.cpid_;
590     lac_ = tdscdmaCell.lac_;
591     timeStamp_ = tdscdmaCell.timeStamp_;
592     signalLevel_ = tdscdmaCell.signalLevel_;
593     signalIntensity_ = tdscdmaCell.signalIntensity_;
594     isCamped_ = tdscdmaCell.isCamped_;
595     return *this;
596 }
597 
operator ==(const TdscdmaCellInformation & other) const598 bool TdscdmaCellInformation::operator==(const TdscdmaCellInformation &other) const
599 {
600     return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
601         uarfcn_ == other.uarfcn_ && cellId_ == other.cellId_ &&
602         cpid_ == other.cpid_ && lac_ == other.lac_ &&
603         signalLevel_ == other.signalLevel_ && signalIntensity_ == other.signalIntensity_ &&
604         isCamped_ == other.isCamped_;
605 }
606 
GetNetworkType() const607 CellInformation::CellType TdscdmaCellInformation::GetNetworkType() const
608 {
609     return CellType::CELL_TYPE_TDSCDMA;
610 }
611 
GetArfcn() const612 int32_t TdscdmaCellInformation::GetArfcn() const
613 {
614     return uarfcn_;
615 }
616 
Marshalling(Parcel & parcel) const617 bool TdscdmaCellInformation::Marshalling(Parcel &parcel) const
618 {
619     if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_TDSCDMA))) {
620         return false;
621     }
622     if (!parcel.WriteString(mcc_)) {
623         return false;
624     }
625     if (!parcel.WriteString(mnc_)) {
626         return false;
627     }
628     if (!parcel.WriteInt32(uarfcn_)) {
629         return false;
630     }
631     if (!parcel.WriteInt32(cellId_)) {
632         return false;
633     }
634     if (!parcel.WriteInt32(cpid_)) {
635         return false;
636     }
637     if (!parcel.WriteInt32(lac_)) {
638         return false;
639     }
640     if (!parcel.WriteUint64(timeStamp_)) {
641         return false;
642     }
643     if (!parcel.WriteInt32(signalLevel_)) {
644         return false;
645     }
646     if (!parcel.WriteInt32(signalIntensity_)) {
647         return false;
648     }
649     if (!parcel.WriteBool(isCamped_)) {
650         return false;
651     }
652     return true;
653 }
654 
Unmarshalling(Parcel & parcel)655 TdscdmaCellInformation *TdscdmaCellInformation::Unmarshalling(Parcel &parcel)
656 {
657     TdscdmaCellInformation *param = new (std::nothrow) TdscdmaCellInformation();
658     if (param == nullptr) {
659         return nullptr;
660     }
661     if (!param->ReadFromParcel(parcel)) {
662         delete param;
663         param = nullptr;
664     }
665     return param;
666 }
667 
ReadFromParcel(Parcel & parcel)668 bool TdscdmaCellInformation::ReadFromParcel(Parcel &parcel)
669 {
670     mcc_ = parcel.ReadString();
671     mnc_ = parcel.ReadString();
672     uarfcn_ = parcel.ReadInt32();
673     cellId_ = parcel.ReadInt32();
674     cpid_ = parcel.ReadInt32();
675     lac_ = parcel.ReadInt32();
676     timeStamp_ = parcel.ReadUint64();
677     signalLevel_ = parcel.ReadInt32();
678     signalIntensity_ = parcel.ReadInt32();
679     isCamped_ = parcel.ReadBool();
680     return true;
681 }
682 
GetCpid() const683 int32_t TdscdmaCellInformation::GetCpid() const
684 {
685     return cpid_;
686 }
687 
GetLac() const688 int32_t TdscdmaCellInformation::GetLac() const
689 {
690     return lac_;
691 }
692 
UpdateLocation(int32_t cellId,int32_t lac)693 void TdscdmaCellInformation::UpdateLocation(int32_t cellId, int32_t lac)
694 {
695     cellId_ = cellId;
696     lac_ = lac;
697     timeStamp_ = time(0);
698 }
699 
ToString() const700 std::string TdscdmaCellInformation::ToString() const
701 {
702     int32_t netWorkType = static_cast<int32_t>(TdscdmaCellInformation::GetNetworkType());
703     std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
704         ",mnc:" + mnc_ + ",uarfcn:" + std::to_string(uarfcn_) + ",cellId:" + std::to_string(cellId_) +
705         ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
706         ",signalIntensity:" + std::to_string(signalIntensity_) + ",cpid:" + std::to_string(cpid_) +
707         ",lac:" + std::to_string(lac_));
708     return content;
709 }
710 
SetCdmaParam(int32_t baseId,int32_t latitude,int32_t longitude,int32_t nid,int32_t sid)711 void CdmaCellInformation::SetCdmaParam(int32_t baseId, int32_t latitude, int32_t longitude, int32_t nid, int32_t sid)
712 {
713     baseId_ = baseId;
714     latitude_ = latitude;
715     longitude_ = longitude;
716     nid_ = nid;
717     sid_ = sid;
718 }
719 
CdmaCellInformation(const CdmaCellInformation & cdmaCell)720 CdmaCellInformation::CdmaCellInformation(const CdmaCellInformation &cdmaCell)
721 {
722     baseId_ = cdmaCell.baseId_;
723     latitude_ = cdmaCell.latitude_;
724     longitude_ = cdmaCell.longitude_;
725     nid_ = cdmaCell.nid_;
726     sid_ = cdmaCell.sid_;
727     timeStamp_ = cdmaCell.timeStamp_;
728     signalLevel_ = cdmaCell.signalLevel_;
729     signalIntensity_ = cdmaCell.signalIntensity_;
730     isCamped_ = cdmaCell.isCamped_;
731 }
732 
operator =(const CdmaCellInformation & cdmaCell)733 CdmaCellInformation &CdmaCellInformation::operator=(const CdmaCellInformation &cdmaCell)
734 {
735     baseId_ = cdmaCell.baseId_;
736     latitude_ = cdmaCell.latitude_;
737     longitude_ = cdmaCell.longitude_;
738     nid_ = cdmaCell.nid_;
739     sid_ = cdmaCell.sid_;
740     timeStamp_ = cdmaCell.timeStamp_;
741     signalLevel_ = cdmaCell.signalLevel_;
742     signalIntensity_ = cdmaCell.signalIntensity_;
743     isCamped_ = cdmaCell.isCamped_;
744     return *this;
745 }
746 
operator ==(const CdmaCellInformation & other) const747 bool CdmaCellInformation::operator==(const CdmaCellInformation &other) const
748 {
749     return baseId_ == other.baseId_ && latitude_ == other.latitude_ &&
750         longitude_ == other.longitude_ && nid_ == other.nid_ &&
751         sid_ == other.sid_ && signalLevel_ == other.signalLevel_ &&
752         signalIntensity_ == other.signalIntensity_ && isCamped_ == other.isCamped_;
753 }
754 
GetNetworkType() const755 CellInformation::CellType CdmaCellInformation::GetNetworkType() const
756 {
757     return CellType::CELL_TYPE_CDMA;
758 }
759 
Marshalling(Parcel & parcel) const760 bool CdmaCellInformation::Marshalling(Parcel &parcel) const
761 {
762     if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_CDMA))) {
763         return false;
764     }
765     if (!parcel.WriteInt32(baseId_)) {
766         return false;
767     }
768     if (!parcel.WriteInt32(latitude_)) {
769         return false;
770     }
771     if (!parcel.WriteInt32(longitude_)) {
772         return false;
773     }
774     if (!parcel.WriteInt32(nid_)) {
775         return false;
776     }
777     if (!parcel.WriteInt32(sid_)) {
778         return false;
779     }
780     if (!parcel.WriteUint64(timeStamp_)) {
781         return false;
782     }
783     if (!parcel.WriteInt32(signalLevel_)) {
784         return false;
785     }
786     if (!parcel.WriteInt32(signalIntensity_)) {
787         return false;
788     }
789     if (!parcel.WriteBool(isCamped_)) {
790         return false;
791     }
792     return true;
793 }
794 
Unmarshalling(Parcel & parcel)795 CdmaCellInformation *CdmaCellInformation::Unmarshalling(Parcel &parcel)
796 {
797     CdmaCellInformation *param = new (std::nothrow) CdmaCellInformation();
798     if (param == nullptr) {
799         return nullptr;
800     }
801     if (!param->ReadFromParcel(parcel)) {
802         delete param;
803         param = nullptr;
804     }
805     return param;
806 }
807 
ReadFromParcel(Parcel & parcel)808 bool CdmaCellInformation::ReadFromParcel(Parcel &parcel)
809 {
810     baseId_ = parcel.ReadInt32();
811     latitude_ = parcel.ReadInt32();
812     longitude_ = parcel.ReadInt32();
813     nid_ = parcel.ReadInt32();
814     sid_ = parcel.ReadInt32();
815     timeStamp_ = parcel.ReadUint64();
816     signalLevel_ = parcel.ReadInt32();
817     signalIntensity_ = parcel.ReadInt32();
818     isCamped_ = parcel.ReadBool();
819     return true;
820 }
821 
GetBaseId() const822 int32_t CdmaCellInformation::GetBaseId() const
823 {
824     return baseId_;
825 }
826 
GetLatitude() const827 int32_t CdmaCellInformation::GetLatitude() const
828 {
829     return latitude_;
830 }
831 
GetLongitude() const832 int32_t CdmaCellInformation::GetLongitude() const
833 {
834     return longitude_;
835 }
836 
GetNid() const837 int32_t CdmaCellInformation::GetNid() const
838 {
839     return nid_;
840 }
841 
GetSid() const842 int32_t CdmaCellInformation::GetSid() const
843 {
844     return sid_;
845 }
846 
UpdateLocation(int32_t baseId,int32_t latitude,int32_t longitude)847 void CdmaCellInformation::UpdateLocation(int32_t baseId, int32_t latitude, int32_t longitude)
848 {
849     baseId_ = baseId;
850     latitude_ = latitude;
851     longitude_ = longitude;
852     timeStamp_ = time(0);
853 }
854 
ToString() const855 std::string CdmaCellInformation::ToString() const
856 {
857     int32_t netWorkType = static_cast<int32_t>(CdmaCellInformation::GetNetworkType());
858     std::string content("netWorkType:" + std::to_string(netWorkType) + ",baseId:" + std::to_string(baseId_) +
859         ",latitude:" + std::to_string(latitude_) + ",longitude:" + std::to_string(longitude_) +
860         ",nid:" + std::to_string(nid_) + ",timeStamp:" + std::to_string(timeStamp_) +
861         ",signalLevel:" + std::to_string(signalLevel_) + ",signalIntensity:" + std::to_string(signalIntensity_) +
862         ",sid:" + std::to_string(sid_));
863     return content;
864 }
865 
SetNrParam(int32_t nrArfcn,int32_t pci,int32_t tac,int64_t nci)866 void NrCellInformation::SetNrParam(int32_t nrArfcn, int32_t pci, int32_t tac, int64_t nci)
867 {
868     nrArfcn_ = nrArfcn;
869     pci_ = pci;
870     tac_ = tac;
871     nci_ = nci;
872 }
873 
NrCellInformation(const NrCellInformation & nrCell)874 NrCellInformation::NrCellInformation(const NrCellInformation &nrCell)
875 {
876     mcc_ = nrCell.mcc_;
877     mnc_ = nrCell.mnc_;
878     cellId_ = nrCell.cellId_;
879     nrArfcn_ = nrCell.nrArfcn_;
880     pci_ = nrCell.pci_;
881     tac_ = nrCell.tac_;
882     nci_ = nrCell.nci_;
883     timeStamp_ = nrCell.timeStamp_;
884     signalLevel_ = nrCell.signalLevel_;
885     signalIntensity_ = nrCell.signalIntensity_;
886     isCamped_ = nrCell.isCamped_;
887 }
888 
operator =(const NrCellInformation & nrCell)889 NrCellInformation &NrCellInformation::operator=(const NrCellInformation &nrCell)
890 {
891     mcc_ = nrCell.mcc_;
892     mnc_ = nrCell.mnc_;
893     cellId_ = nrCell.cellId_;
894     nrArfcn_ = nrCell.nrArfcn_;
895     pci_ = nrCell.pci_;
896     tac_ = nrCell.tac_;
897     nci_ = nrCell.nci_;
898     timeStamp_ = nrCell.timeStamp_;
899     signalLevel_ = nrCell.signalLevel_;
900     signalIntensity_ = nrCell.signalIntensity_;
901     isCamped_ = nrCell.isCamped_;
902     return *this;
903 }
904 
operator ==(const NrCellInformation & other) const905 bool NrCellInformation::operator==(const NrCellInformation &other) const
906 {
907     return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
908         cellId_ == other.cellId_ && nrArfcn_ == other.nrArfcn_ &&
909         pci_ == other.pci_ && tac_ == other.tac_ && nci_ == other.nci_ &&
910         signalLevel_ == other.signalLevel_ && signalIntensity_ == other.signalIntensity_ &&
911         isCamped_ == other.isCamped_;
912 }
913 
GetNetworkType() const914 CellInformation::CellType NrCellInformation::GetNetworkType() const
915 {
916     return CellType::CELL_TYPE_NR;
917 }
918 
Marshalling(Parcel & parcel) const919 bool NrCellInformation::Marshalling(Parcel &parcel) const
920 {
921     if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_NR))) {
922         return false;
923     }
924     if (!parcel.WriteString(mcc_)) {
925         return false;
926     }
927     if (!parcel.WriteString(mnc_)) {
928         return false;
929     }
930     if (!parcel.WriteInt32(cellId_)) {
931         return false;
932     }
933     if (!parcel.WriteInt32(nrArfcn_)) {
934         return false;
935     }
936     if (!parcel.WriteInt32(pci_)) {
937         return false;
938     }
939     if (!parcel.WriteInt32(tac_)) {
940         return false;
941     }
942     if (!parcel.WriteInt64(nci_)) {
943         return false;
944     }
945     if (!parcel.WriteInt64(timeStamp_)) {
946         return false;
947     }
948     if (!parcel.WriteInt32(signalLevel_)) {
949         return false;
950     }
951     if (!parcel.WriteInt32(signalIntensity_)) {
952         return false;
953     }
954     if (!parcel.WriteBool(isCamped_)) {
955         return false;
956     }
957     return true;
958 }
959 
Unmarshalling(Parcel & parcel)960 NrCellInformation *NrCellInformation::Unmarshalling(Parcel &parcel)
961 {
962     NrCellInformation *param = new (std::nothrow) NrCellInformation();
963     if (param == nullptr) {
964         return nullptr;
965     }
966     if (!param->ReadFromParcel(parcel)) {
967         delete param;
968         param = nullptr;
969     }
970     return param;
971 }
972 
ReadFromParcel(Parcel & parcel)973 bool NrCellInformation::ReadFromParcel(Parcel &parcel)
974 {
975     mcc_ = parcel.ReadString();
976     mnc_ = parcel.ReadString();
977     cellId_ = parcel.ReadInt32();
978     nrArfcn_ = parcel.ReadInt32();
979     pci_ = parcel.ReadInt32();
980     tac_ = parcel.ReadInt32();
981     nci_ = parcel.ReadInt64();
982     timeStamp_ = parcel.ReadInt64();
983     signalLevel_ = parcel.ReadInt32();
984     signalIntensity_ = parcel.ReadInt32();
985     isCamped_ = parcel.ReadBool();
986     return true;
987 }
988 
GetArfcn() const989 int32_t NrCellInformation::GetArfcn() const
990 {
991     return nrArfcn_;
992 }
993 
GetPci() const994 int32_t NrCellInformation::GetPci() const
995 {
996     return pci_;
997 }
998 
GetTac() const999 int32_t NrCellInformation::GetTac() const
1000 {
1001     return tac_;
1002 }
1003 
GetNci() const1004 int64_t NrCellInformation::GetNci() const
1005 {
1006     return nci_;
1007 }
1008 
UpdateLocation(int32_t pci,int32_t tac)1009 void NrCellInformation::UpdateLocation(int32_t pci, int32_t tac)
1010 {
1011     pci_ = pci;
1012     tac_ = tac;
1013     timeStamp_ = time(0);
1014 }
1015 
ToString() const1016 std::string NrCellInformation::ToString() const
1017 {
1018     int32_t netWorkType = static_cast<int32_t>(NrCellInformation::GetNetworkType());
1019     std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
1020         ",mnc:" + mnc_ + ",earfcn:" + std::to_string(nrArfcn_) + ",cellId:" + std::to_string(cellId_) +
1021         ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
1022         ",signalIntensity:" + std::to_string(signalIntensity_) + ",pci:" + std::to_string(pci_) +
1023         ",tac:" + std::to_string(tac_) + ",nci:" + std::to_string(nci_));
1024     return content;
1025 }
1026 } // namespace Telephony
1027 } // namespace OHOS
1028