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 <ctime>
20 #include <memory>
21 #include <securec.h>
22
23 #include "iosfwd"
24 #include "new"
25 #include "parcel.h"
26 #include "string"
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 std::string readString;
234 if (!parcel.ReadString(readString)) {
235 return false;
236 }
237 mcc_ = readString;
238 if (!parcel.ReadString(readString)) {
239 return false;
240 }
241 mnc_ = readString;
242 int32_t rat;
243 if (!parcel.ReadInt32(rat)) {
244 return false;
245 }
246 arfcn_ = rat;
247 if (!parcel.ReadInt32(rat)) {
248 return false;
249 }
250 cellId_ = rat;
251 if (!parcel.ReadInt32(rat)) {
252 return false;
253 }
254 bsic_ = rat;
255 if (!parcel.ReadInt32(rat)) {
256 return false;
257 }
258 lac_ = rat;
259 uint64_t gsmTime = 0;
260 if (!parcel.ReadUint64(gsmTime)) {
261 return false;
262 }
263 timeStamp_ = gsmTime;
264 if (!parcel.ReadInt32(rat)) {
265 return false;
266 }
267 signalLevel_ = rat;
268 int32_t gsmSignalIntensity = 0;
269 if (!parcel.ReadInt32(gsmSignalIntensity)) {
270 return false;
271 }
272 signalIntensity_ = gsmSignalIntensity;
273 bool gsmTemCamped = false;
274 if (!parcel.ReadBool(gsmTemCamped)) {
275 return false;
276 }
277 isCamped_ = gsmTemCamped;
278
279 return true;
280 }
281
GetLac() const282 int32_t GsmCellInformation::GetLac() const
283 {
284 return lac_;
285 }
286
GetBsic() const287 int32_t GsmCellInformation::GetBsic() const
288 {
289 return bsic_;
290 }
291
UpdateLocation(int32_t cellId,int32_t lac)292 void GsmCellInformation::UpdateLocation(int32_t cellId, int32_t lac)
293 {
294 cellId_ = cellId;
295 lac_ = lac;
296 timeStamp_ = time(0);
297 }
298
SetLteParam(int32_t pci,int32_t tac,int32_t arfcn)299 void LteCellInformation::SetLteParam(int32_t pci, int32_t tac, int32_t arfcn)
300 {
301 pci_ = pci;
302 tac_ = tac;
303 earfcn_ = arfcn;
304 }
305
LteCellInformation(const LteCellInformation & lteCell)306 LteCellInformation::LteCellInformation(const LteCellInformation <eCell)
307 {
308 mcc_ = lteCell.mcc_;
309 mnc_ = lteCell.mnc_;
310 earfcn_ = lteCell.earfcn_;
311 cellId_ = lteCell.cellId_;
312 pci_ = lteCell.pci_;
313 tac_ = lteCell.tac_;
314 timeStamp_ = lteCell.timeStamp_;
315 signalLevel_ = lteCell.signalLevel_;
316 signalIntensity_ = lteCell.signalIntensity_;
317 isCamped_ = lteCell.isCamped_;
318 }
319
operator =(const LteCellInformation & lteCell)320 LteCellInformation &LteCellInformation::operator=(const LteCellInformation <eCell)
321 {
322 mcc_ = lteCell.mcc_;
323 mnc_ = lteCell.mnc_;
324 earfcn_ = lteCell.earfcn_;
325 cellId_ = lteCell.cellId_;
326 pci_ = lteCell.pci_;
327 tac_ = lteCell.tac_;
328 timeStamp_ = lteCell.timeStamp_;
329 signalLevel_ = lteCell.signalLevel_;
330 signalIntensity_ = lteCell.signalIntensity_;
331 isCamped_ = lteCell.isCamped_;
332 return *this;
333 }
334
operator ==(const LteCellInformation & other) const335 bool LteCellInformation::operator==(const LteCellInformation &other) const
336 {
337 return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
338 earfcn_ == other.earfcn_ && cellId_ == other.cellId_ &&
339 pci_ == other.pci_ && tac_ == other.tac_ &&
340 signalLevel_ == other.signalLevel_ && signalIntensity_ == other.signalIntensity_ &&
341 isCamped_ == other.isCamped_;
342 }
343
GetNetworkType() const344 CellInformation::CellType LteCellInformation::GetNetworkType() const
345 {
346 return CellType::CELL_TYPE_LTE;
347 }
348
GetArfcn() const349 int32_t LteCellInformation::GetArfcn() const
350 {
351 return earfcn_;
352 }
353
Marshalling(Parcel & parcel) const354 bool LteCellInformation::Marshalling(Parcel &parcel) const
355 {
356 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_LTE))) {
357 return false;
358 }
359 if (!parcel.WriteString(mcc_)) {
360 return false;
361 }
362 if (!parcel.WriteString(mnc_)) {
363 return false;
364 }
365 if (!parcel.WriteInt32(earfcn_)) {
366 return false;
367 }
368 if (!parcel.WriteInt32(cellId_)) {
369 return false;
370 }
371 if (!parcel.WriteInt32(pci_)) {
372 return false;
373 }
374 if (!parcel.WriteInt32(tac_)) {
375 return false;
376 }
377 if (!parcel.WriteInt64(timeStamp_)) {
378 return false;
379 }
380 if (!parcel.WriteInt32(signalLevel_)) {
381 return false;
382 }
383 if (!parcel.WriteInt32(signalIntensity_)) {
384 return false;
385 }
386 if (!parcel.WriteBool(isCamped_)) {
387 return false;
388 }
389 return true;
390 }
391
Unmarshalling(Parcel & parcel)392 LteCellInformation *LteCellInformation::Unmarshalling(Parcel &parcel)
393 {
394 LteCellInformation *param = new (std::nothrow) LteCellInformation();
395 if (param == nullptr) {
396 return nullptr;
397 }
398 if (!param->ReadFromParcel(parcel)) {
399 delete param;
400 param = nullptr;
401 }
402 return param;
403 }
404
ReadFromParcel(Parcel & parcel)405 bool LteCellInformation::ReadFromParcel(Parcel &parcel)
406 {
407 std::string readString;
408 if (!parcel.ReadString(readString)) {
409 return false;
410 }
411 mcc_ = readString;
412 if (!parcel.ReadString(readString)) {
413 return false;
414 }
415 mnc_ = readString;
416 int32_t rat;
417 if (!parcel.ReadInt32(rat)) {
418 return false;
419 }
420 earfcn_ = rat;
421 if (!parcel.ReadInt32(rat)) {
422 return false;
423 }
424 cellId_ = rat;
425 if (!parcel.ReadInt32(rat)) {
426 return false;
427 }
428 pci_ = rat;
429 if (!parcel.ReadInt32(rat)) {
430 return false;
431 }
432 tac_ = rat;
433 uint64_t lteTime = 0;
434 if (!parcel.ReadUint64(lteTime)) {
435 return false;
436 }
437 timeStamp_ = lteTime;
438 if (!parcel.ReadInt32(rat)) {
439 return false;
440 }
441 signalLevel_ = rat;
442 int32_t lteSignalIntensity = 0;
443 if (!parcel.ReadInt32(lteSignalIntensity)) {
444 return false;
445 }
446 signalIntensity_ = lteSignalIntensity;
447 bool lteTemCamped = false;
448 if (!parcel.ReadBool(lteTemCamped)) {
449 return false;
450 }
451 isCamped_ = lteTemCamped;
452 return true;
453 }
454
GetPci() const455 int32_t LteCellInformation::GetPci() const
456 {
457 return pci_;
458 }
459
GetTac() const460 int32_t LteCellInformation::GetTac() const
461 {
462 return tac_;
463 }
464
UpdateLocation(int32_t cellId,int32_t tac)465 void LteCellInformation::UpdateLocation(int32_t cellId, int32_t tac)
466 {
467 cellId_ = cellId;
468 tac_ = tac;
469 timeStamp_ = static_cast<uint64_t>(time(0));
470 }
471
ToString() const472 std::string LteCellInformation::ToString() const
473 {
474 int32_t netWorkType = static_cast<int32_t>(LteCellInformation::GetNetworkType());
475 std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
476 ",mnc:" + mnc_ + ",earfcn:" + std::to_string(earfcn_) + ",cellId:" + std::to_string(cellId_) +
477 ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
478 ",signalIntensity:" + std::to_string(signalIntensity_) + ",pci:" + std::to_string(pci_) +
479 ",pci:" + std::to_string(pci_) + ",tac:" + std::to_string(tac_));
480 return content;
481 }
482
SetWcdmaParam(int32_t psc,int32_t lac,int32_t arfcn)483 void WcdmaCellInformation::SetWcdmaParam(int32_t psc, int32_t lac, int32_t arfcn)
484 {
485 psc_ = psc;
486 lac_ = lac;
487 uarfcn_ = arfcn;
488 }
489
WcdmaCellInformation(const WcdmaCellInformation & wcdmaCell)490 WcdmaCellInformation::WcdmaCellInformation(const WcdmaCellInformation &wcdmaCell)
491 {
492 mcc_ = wcdmaCell.mcc_;
493 mnc_ = wcdmaCell.mnc_;
494 uarfcn_ = wcdmaCell.uarfcn_;
495 cellId_ = wcdmaCell.cellId_;
496 psc_ = wcdmaCell.psc_;
497 lac_ = wcdmaCell.lac_;
498 timeStamp_ = wcdmaCell.timeStamp_;
499 signalLevel_ = wcdmaCell.signalLevel_;
500 signalIntensity_ = wcdmaCell.signalIntensity_;
501 isCamped_ = wcdmaCell.isCamped_;
502 }
503
operator =(const WcdmaCellInformation & wcdmaCell)504 WcdmaCellInformation &WcdmaCellInformation::operator=(const WcdmaCellInformation &wcdmaCell)
505 {
506 mcc_ = wcdmaCell.mcc_;
507 mnc_ = wcdmaCell.mnc_;
508 uarfcn_ = wcdmaCell.uarfcn_;
509 cellId_ = wcdmaCell.cellId_;
510 psc_ = wcdmaCell.psc_;
511 lac_ = wcdmaCell.lac_;
512 timeStamp_ = wcdmaCell.timeStamp_;
513 signalLevel_ = wcdmaCell.signalLevel_;
514 signalIntensity_ = wcdmaCell.signalIntensity_;
515 isCamped_ = wcdmaCell.isCamped_;
516 return *this;
517 }
518
operator ==(const WcdmaCellInformation & other) const519 bool WcdmaCellInformation::operator==(const WcdmaCellInformation &other) const
520 {
521 return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
522 uarfcn_ == other.uarfcn_ && cellId_ == other.cellId_ &&
523 psc_ == other.psc_ && lac_ == other.lac_ &&
524 signalLevel_ == other.signalLevel_ && signalIntensity_ == other.signalIntensity_ &&
525 isCamped_ == other.isCamped_;
526 }
527
GetNetworkType() const528 CellInformation::CellType WcdmaCellInformation::GetNetworkType() const
529 {
530 return CellType::CELL_TYPE_WCDMA;
531 }
532
GetArfcn() const533 int32_t WcdmaCellInformation::GetArfcn() const
534 {
535 return uarfcn_;
536 }
537
Marshalling(Parcel & parcel) const538 bool WcdmaCellInformation::Marshalling(Parcel &parcel) const
539 {
540 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_WCDMA))) {
541 return false;
542 }
543 if (!parcel.WriteString(mcc_)) {
544 return false;
545 }
546 if (!parcel.WriteString(mnc_)) {
547 return false;
548 }
549 if (!parcel.WriteInt32(uarfcn_)) {
550 return false;
551 }
552 if (!parcel.WriteInt32(cellId_)) {
553 return false;
554 }
555 if (!parcel.WriteInt32(psc_)) {
556 return false;
557 }
558 if (!parcel.WriteInt32(lac_)) {
559 return false;
560 }
561 if (!parcel.WriteInt64(timeStamp_)) {
562 return false;
563 }
564 if (!parcel.WriteInt32(signalLevel_)) {
565 return false;
566 }
567 if (!parcel.WriteInt32(signalIntensity_)) {
568 return false;
569 }
570 if (!parcel.WriteBool(isCamped_)) {
571 return false;
572 }
573 return true;
574 }
575
Unmarshalling(Parcel & parcel)576 WcdmaCellInformation *WcdmaCellInformation::Unmarshalling(Parcel &parcel)
577 {
578 WcdmaCellInformation *param = new (std::nothrow) WcdmaCellInformation();
579 if (param == nullptr) {
580 return nullptr;
581 }
582 if (!param->ReadFromParcel(parcel)) {
583 delete param;
584 param = nullptr;
585 }
586 return param;
587 }
588
ReadFromParcel(Parcel & parcel)589 bool WcdmaCellInformation::ReadFromParcel(Parcel &parcel)
590 {
591 std::string readString;
592 if (!parcel.ReadString(readString)) {
593 return false;
594 }
595 mcc_ = readString;
596 if (!parcel.ReadString(readString)) {
597 return false;
598 }
599 mnc_ = readString;
600 int32_t rat;
601 if (!parcel.ReadInt32(rat)) {
602 return false;
603 }
604 uarfcn_ = rat;
605 if (!parcel.ReadInt32(rat)) {
606 return false;
607 }
608 cellId_ = rat;
609 if (!parcel.ReadInt32(rat)) {
610 return false;
611 }
612 psc_ = rat;
613 if (!parcel.ReadInt32(rat)) {
614 return false;
615 }
616 lac_ = rat;
617 uint64_t wcdmaTime = 0;
618 if (!parcel.ReadUint64(wcdmaTime)) {
619 return false;
620 }
621 timeStamp_ = wcdmaTime;
622 if (!parcel.ReadInt32(rat)) {
623 return false;
624 }
625 signalLevel_ = rat;
626 int32_t wcdmaSignalIntensity = 0;
627 if (!parcel.ReadInt32(wcdmaSignalIntensity)) {
628 return false;
629 }
630 signalIntensity_ = wcdmaSignalIntensity;
631 bool wcdmaTemCamped = false;
632 if (!parcel.ReadBool(wcdmaTemCamped)) {
633 return false;
634 }
635 isCamped_ = wcdmaTemCamped;
636 return true;
637 }
638
GetPsc() const639 int32_t WcdmaCellInformation::GetPsc() const
640 {
641 return psc_;
642 }
643
GetLac() const644 int32_t WcdmaCellInformation::GetLac() const
645 {
646 return lac_;
647 }
648
UpdateLocation(int32_t cellId,int32_t lac)649 void WcdmaCellInformation::UpdateLocation(int32_t cellId, int32_t lac)
650 {
651 cellId_ = cellId;
652 lac_ = lac;
653 timeStamp_ = time(0);
654 }
655
ToString() const656 std::string WcdmaCellInformation::ToString() const
657 {
658 int32_t netWorkType = static_cast<int32_t>(WcdmaCellInformation::GetNetworkType());
659 std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
660 ",mnc:" + mnc_ + ",uarfcn:" + std::to_string(uarfcn_) + ",cellId:" + std::to_string(cellId_) +
661 ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
662 ",signalIntensity:" + std::to_string(signalIntensity_) + ",psc:" + std::to_string(psc_) +
663 ",lac:" + std::to_string(lac_));
664 return content;
665 }
666
SetTdscdmaParam(int32_t cpid,int32_t lac,int32_t arfcn)667 void TdscdmaCellInformation::SetTdscdmaParam(int32_t cpid, int32_t lac, int32_t arfcn)
668 {
669 cpid_ = cpid;
670 lac_ = lac;
671 uarfcn_ = arfcn;
672 }
673
TdscdmaCellInformation(const TdscdmaCellInformation & tdscdmaCell)674 TdscdmaCellInformation::TdscdmaCellInformation(const TdscdmaCellInformation &tdscdmaCell)
675 {
676 mcc_ = tdscdmaCell.mcc_;
677 mnc_ = tdscdmaCell.mnc_;
678 uarfcn_ = tdscdmaCell.uarfcn_;
679 cellId_ = tdscdmaCell.cellId_;
680 cpid_ = tdscdmaCell.cpid_;
681 lac_ = tdscdmaCell.lac_;
682 timeStamp_ = tdscdmaCell.timeStamp_;
683 signalLevel_ = tdscdmaCell.signalLevel_;
684 signalIntensity_ = tdscdmaCell.signalIntensity_;
685 isCamped_ = tdscdmaCell.isCamped_;
686 }
687
operator =(const TdscdmaCellInformation & tdscdmaCell)688 TdscdmaCellInformation &TdscdmaCellInformation::operator=(const TdscdmaCellInformation &tdscdmaCell)
689 {
690 mcc_ = tdscdmaCell.mcc_;
691 mnc_ = tdscdmaCell.mnc_;
692 uarfcn_ = tdscdmaCell.uarfcn_;
693 cellId_ = tdscdmaCell.cellId_;
694 cpid_ = tdscdmaCell.cpid_;
695 lac_ = tdscdmaCell.lac_;
696 timeStamp_ = tdscdmaCell.timeStamp_;
697 signalLevel_ = tdscdmaCell.signalLevel_;
698 signalIntensity_ = tdscdmaCell.signalIntensity_;
699 isCamped_ = tdscdmaCell.isCamped_;
700 return *this;
701 }
702
operator ==(const TdscdmaCellInformation & other) const703 bool TdscdmaCellInformation::operator==(const TdscdmaCellInformation &other) const
704 {
705 return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
706 uarfcn_ == other.uarfcn_ && cellId_ == other.cellId_ &&
707 cpid_ == other.cpid_ && lac_ == other.lac_ &&
708 signalLevel_ == other.signalLevel_ && signalIntensity_ == other.signalIntensity_ &&
709 isCamped_ == other.isCamped_;
710 }
711
GetNetworkType() const712 CellInformation::CellType TdscdmaCellInformation::GetNetworkType() const
713 {
714 return CellType::CELL_TYPE_TDSCDMA;
715 }
716
GetArfcn() const717 int32_t TdscdmaCellInformation::GetArfcn() const
718 {
719 return uarfcn_;
720 }
721
Marshalling(Parcel & parcel) const722 bool TdscdmaCellInformation::Marshalling(Parcel &parcel) const
723 {
724 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_TDSCDMA))) {
725 return false;
726 }
727 if (!parcel.WriteString(mcc_)) {
728 return false;
729 }
730 if (!parcel.WriteString(mnc_)) {
731 return false;
732 }
733 if (!parcel.WriteInt32(uarfcn_)) {
734 return false;
735 }
736 if (!parcel.WriteInt32(cellId_)) {
737 return false;
738 }
739 if (!parcel.WriteInt32(cpid_)) {
740 return false;
741 }
742 if (!parcel.WriteInt32(lac_)) {
743 return false;
744 }
745 if (!parcel.WriteUint64(timeStamp_)) {
746 return false;
747 }
748 if (!parcel.WriteInt32(signalLevel_)) {
749 return false;
750 }
751 if (!parcel.WriteInt32(signalIntensity_)) {
752 return false;
753 }
754 if (!parcel.WriteBool(isCamped_)) {
755 return false;
756 }
757 return true;
758 }
759
Unmarshalling(Parcel & parcel)760 TdscdmaCellInformation *TdscdmaCellInformation::Unmarshalling(Parcel &parcel)
761 {
762 TdscdmaCellInformation *param = new (std::nothrow) TdscdmaCellInformation();
763 if (param == nullptr) {
764 return nullptr;
765 }
766 if (!param->ReadFromParcel(parcel)) {
767 delete param;
768 param = nullptr;
769 }
770 return param;
771 }
772
ReadFromParcel(Parcel & parcel)773 bool TdscdmaCellInformation::ReadFromParcel(Parcel &parcel)
774 {
775 std::string readString;
776 if (!parcel.ReadString(readString)) {
777 return false;
778 }
779 mcc_ = readString;
780 if (!parcel.ReadString(readString)) {
781 return false;
782 }
783 mnc_ = readString;
784 int32_t rat;
785 if (!parcel.ReadInt32(rat)) {
786 return false;
787 }
788 uarfcn_ = rat;
789 if (!parcel.ReadInt32(rat)) {
790 return false;
791 }
792 cellId_ = rat;
793 if (!parcel.ReadInt32(rat)) {
794 return false;
795 }
796 cpid_ = rat;
797 if (!parcel.ReadInt32(rat)) {
798 return false;
799 }
800 lac_ = rat;
801 uint64_t tdscdmaTime = 0;
802 if (!parcel.ReadUint64(tdscdmaTime)) {
803 return false;
804 }
805 timeStamp_ = tdscdmaTime;
806 if (!parcel.ReadInt32(rat)) {
807 return false;
808 }
809 signalLevel_ = rat;
810 int32_t tdscdmaSignalIntensity = 0;
811 if (!parcel.ReadInt32(tdscdmaSignalIntensity)) {
812 return false;
813 }
814 signalIntensity_ = tdscdmaSignalIntensity;
815 bool tdscdmaTemCamped = false;
816 if (!parcel.ReadBool(tdscdmaTemCamped)) {
817 return false;
818 }
819 isCamped_ = tdscdmaTemCamped;
820 return true;
821 }
822
GetCpid() const823 int32_t TdscdmaCellInformation::GetCpid() const
824 {
825 return cpid_;
826 }
827
GetLac() const828 int32_t TdscdmaCellInformation::GetLac() const
829 {
830 return lac_;
831 }
832
UpdateLocation(int32_t cellId,int32_t lac)833 void TdscdmaCellInformation::UpdateLocation(int32_t cellId, int32_t lac)
834 {
835 cellId_ = cellId;
836 lac_ = lac;
837 timeStamp_ = time(0);
838 }
839
ToString() const840 std::string TdscdmaCellInformation::ToString() const
841 {
842 int32_t netWorkType = static_cast<int32_t>(TdscdmaCellInformation::GetNetworkType());
843 std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
844 ",mnc:" + mnc_ + ",uarfcn:" + std::to_string(uarfcn_) + ",cellId:" + std::to_string(cellId_) +
845 ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
846 ",signalIntensity:" + std::to_string(signalIntensity_) + ",cpid:" + std::to_string(cpid_) +
847 ",lac:" + std::to_string(lac_));
848 return content;
849 }
850
SetCdmaParam(int32_t baseId,int32_t latitude,int32_t longitude,int32_t nid,int32_t sid)851 void CdmaCellInformation::SetCdmaParam(int32_t baseId, int32_t latitude, int32_t longitude, int32_t nid, int32_t sid)
852 {
853 baseId_ = baseId;
854 latitude_ = latitude;
855 longitude_ = longitude;
856 nid_ = nid;
857 sid_ = sid;
858 }
859
CdmaCellInformation(const CdmaCellInformation & cdmaCell)860 CdmaCellInformation::CdmaCellInformation(const CdmaCellInformation &cdmaCell)
861 {
862 baseId_ = cdmaCell.baseId_;
863 latitude_ = cdmaCell.latitude_;
864 longitude_ = cdmaCell.longitude_;
865 nid_ = cdmaCell.nid_;
866 sid_ = cdmaCell.sid_;
867 timeStamp_ = cdmaCell.timeStamp_;
868 signalLevel_ = cdmaCell.signalLevel_;
869 signalIntensity_ = cdmaCell.signalIntensity_;
870 isCamped_ = cdmaCell.isCamped_;
871 }
872
operator =(const CdmaCellInformation & cdmaCell)873 CdmaCellInformation &CdmaCellInformation::operator=(const CdmaCellInformation &cdmaCell)
874 {
875 baseId_ = cdmaCell.baseId_;
876 latitude_ = cdmaCell.latitude_;
877 longitude_ = cdmaCell.longitude_;
878 nid_ = cdmaCell.nid_;
879 sid_ = cdmaCell.sid_;
880 timeStamp_ = cdmaCell.timeStamp_;
881 signalLevel_ = cdmaCell.signalLevel_;
882 signalIntensity_ = cdmaCell.signalIntensity_;
883 isCamped_ = cdmaCell.isCamped_;
884 return *this;
885 }
886
operator ==(const CdmaCellInformation & other) const887 bool CdmaCellInformation::operator==(const CdmaCellInformation &other) const
888 {
889 return baseId_ == other.baseId_ && latitude_ == other.latitude_ &&
890 longitude_ == other.longitude_ && nid_ == other.nid_ &&
891 sid_ == other.sid_ && signalLevel_ == other.signalLevel_ &&
892 signalIntensity_ == other.signalIntensity_ && isCamped_ == other.isCamped_;
893 }
894
GetNetworkType() const895 CellInformation::CellType CdmaCellInformation::GetNetworkType() const
896 {
897 return CellType::CELL_TYPE_CDMA;
898 }
899
Marshalling(Parcel & parcel) const900 bool CdmaCellInformation::Marshalling(Parcel &parcel) const
901 {
902 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_CDMA))) {
903 return false;
904 }
905 if (!parcel.WriteInt32(baseId_)) {
906 return false;
907 }
908 if (!parcel.WriteInt32(latitude_)) {
909 return false;
910 }
911 if (!parcel.WriteInt32(longitude_)) {
912 return false;
913 }
914 if (!parcel.WriteInt32(nid_)) {
915 return false;
916 }
917 if (!parcel.WriteInt32(sid_)) {
918 return false;
919 }
920 if (!parcel.WriteUint64(timeStamp_)) {
921 return false;
922 }
923 if (!parcel.WriteInt32(signalLevel_)) {
924 return false;
925 }
926 if (!parcel.WriteInt32(signalIntensity_)) {
927 return false;
928 }
929 if (!parcel.WriteBool(isCamped_)) {
930 return false;
931 }
932 return true;
933 }
934
Unmarshalling(Parcel & parcel)935 CdmaCellInformation *CdmaCellInformation::Unmarshalling(Parcel &parcel)
936 {
937 CdmaCellInformation *param = new (std::nothrow) CdmaCellInformation();
938 if (param == nullptr) {
939 return nullptr;
940 }
941 if (!param->ReadFromParcel(parcel)) {
942 delete param;
943 param = nullptr;
944 }
945 return param;
946 }
947
ReadFromParcel(Parcel & parcel)948 bool CdmaCellInformation::ReadFromParcel(Parcel &parcel)
949 {
950 int32_t rat;
951 if (!parcel.ReadInt32(rat)) {
952 return false;
953 }
954 baseId_ = rat;
955 if (!parcel.ReadInt32(rat)) {
956 return false;
957 }
958 latitude_ = rat;
959 if (!parcel.ReadInt32(rat)) {
960 return false;
961 }
962 longitude_ = rat;
963 if (!parcel.ReadInt32(rat)) {
964 return false;
965 }
966 nid_ = rat;
967 if (!parcel.ReadInt32(rat)) {
968 return false;
969 }
970 sid_ = rat;
971 uint64_t cdmaTime = 0;
972 if (!parcel.ReadUint64(cdmaTime)) {
973 return false;
974 }
975 timeStamp_ = cdmaTime;
976 if (!parcel.ReadInt32(rat)) {
977 return false;
978 }
979 signalLevel_ = rat;
980 int32_t cdmaSignalIntensity = 0;
981 if (!parcel.ReadInt32(cdmaSignalIntensity)) {
982 return false;
983 }
984 signalIntensity_ = cdmaSignalIntensity;
985 bool cdmaTemCamped;
986 if (!parcel.ReadBool(cdmaTemCamped)) {
987 return false;
988 }
989 isCamped_ = cdmaTemCamped;
990 return true;
991 }
992
GetBaseId() const993 int32_t CdmaCellInformation::GetBaseId() const
994 {
995 return baseId_;
996 }
997
GetLatitude() const998 int32_t CdmaCellInformation::GetLatitude() const
999 {
1000 return latitude_;
1001 }
1002
GetLongitude() const1003 int32_t CdmaCellInformation::GetLongitude() const
1004 {
1005 return longitude_;
1006 }
1007
GetNid() const1008 int32_t CdmaCellInformation::GetNid() const
1009 {
1010 return nid_;
1011 }
1012
GetSid() const1013 int32_t CdmaCellInformation::GetSid() const
1014 {
1015 return sid_;
1016 }
1017
UpdateLocation(int32_t baseId,int32_t latitude,int32_t longitude)1018 void CdmaCellInformation::UpdateLocation(int32_t baseId, int32_t latitude, int32_t longitude)
1019 {
1020 baseId_ = baseId;
1021 latitude_ = latitude;
1022 longitude_ = longitude;
1023 timeStamp_ = time(0);
1024 }
1025
ToString() const1026 std::string CdmaCellInformation::ToString() const
1027 {
1028 int32_t netWorkType = static_cast<int32_t>(CdmaCellInformation::GetNetworkType());
1029 std::string content("netWorkType:" + std::to_string(netWorkType) + ",baseId:" + std::to_string(baseId_) +
1030 ",latitude:" + std::to_string(latitude_) + ",longitude:" + std::to_string(longitude_) +
1031 ",nid:" + std::to_string(nid_) + ",timeStamp:" + std::to_string(timeStamp_) +
1032 ",signalLevel:" + std::to_string(signalLevel_) + ",signalIntensity:" + std::to_string(signalIntensity_) +
1033 ",sid:" + std::to_string(sid_));
1034 return content;
1035 }
1036
SetNrParam(int32_t nrArfcn,int32_t pci,int32_t tac,int64_t nci)1037 void NrCellInformation::SetNrParam(int32_t nrArfcn, int32_t pci, int32_t tac, int64_t nci)
1038 {
1039 nrArfcn_ = nrArfcn;
1040 pci_ = pci;
1041 tac_ = tac;
1042 nci_ = nci;
1043 }
1044
SetNrSignalParam(int32_t rsrp,int32_t rsrq)1045 void NrCellInformation::SetNrSignalParam(int32_t rsrp, int32_t rsrq)
1046 {
1047 rsrp_ = rsrp;
1048 rsrq_ = rsrq;
1049 }
1050
NrCellInformation(const NrCellInformation & nrCell)1051 NrCellInformation::NrCellInformation(const NrCellInformation &nrCell)
1052 {
1053 mcc_ = nrCell.mcc_;
1054 mnc_ = nrCell.mnc_;
1055 cellId_ = nrCell.cellId_;
1056 nrArfcn_ = nrCell.nrArfcn_;
1057 pci_ = nrCell.pci_;
1058 tac_ = nrCell.tac_;
1059 nci_ = nrCell.nci_;
1060 rsrp_ = nrCell.rsrp_;
1061 rsrq_ = nrCell.rsrq_;
1062 timeStamp_ = nrCell.timeStamp_;
1063 signalLevel_ = nrCell.signalLevel_;
1064 signalIntensity_ = nrCell.signalIntensity_;
1065 isCamped_ = nrCell.isCamped_;
1066 }
1067
operator =(const NrCellInformation & nrCell)1068 NrCellInformation &NrCellInformation::operator=(const NrCellInformation &nrCell)
1069 {
1070 mcc_ = nrCell.mcc_;
1071 mnc_ = nrCell.mnc_;
1072 cellId_ = nrCell.cellId_;
1073 nrArfcn_ = nrCell.nrArfcn_;
1074 pci_ = nrCell.pci_;
1075 tac_ = nrCell.tac_;
1076 nci_ = nrCell.nci_;
1077 rsrp_ = nrCell.rsrp_;
1078 rsrq_ = nrCell.rsrq_;
1079 timeStamp_ = nrCell.timeStamp_;
1080 signalLevel_ = nrCell.signalLevel_;
1081 signalIntensity_ = nrCell.signalIntensity_;
1082 isCamped_ = nrCell.isCamped_;
1083 return *this;
1084 }
1085
operator ==(const NrCellInformation & other) const1086 bool NrCellInformation::operator==(const NrCellInformation &other) const
1087 {
1088 return mcc_ == other.mcc_ && mnc_ == other.mnc_ && cellId_ == other.cellId_ && nrArfcn_ == other.nrArfcn_ &&
1089 pci_ == other.pci_ && tac_ == other.tac_ && nci_ == other.nci_ && rsrp_ == other.rsrp_ &&
1090 rsrq_ == other.rsrq_ && timeStamp_ == other.timeStamp_ && signalLevel_ == other.signalLevel_ &&
1091 signalIntensity_ == other.signalIntensity_ && isCamped_ == other.isCamped_;
1092 }
1093
GetNetworkType() const1094 CellInformation::CellType NrCellInformation::GetNetworkType() const
1095 {
1096 return CellType::CELL_TYPE_NR;
1097 }
1098
Marshalling(Parcel & parcel) const1099 bool NrCellInformation::Marshalling(Parcel &parcel) const
1100 {
1101 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_NR))) {
1102 return false;
1103 }
1104 if (!parcel.WriteString(mcc_)) {
1105 return false;
1106 }
1107 if (!parcel.WriteString(mnc_)) {
1108 return false;
1109 }
1110 if (!parcel.WriteInt32(cellId_)) {
1111 return false;
1112 }
1113 if (!parcel.WriteInt32(nrArfcn_)) {
1114 return false;
1115 }
1116 if (!parcel.WriteInt32(pci_)) {
1117 return false;
1118 }
1119 if (!parcel.WriteInt32(tac_)) {
1120 return false;
1121 }
1122 if (!parcel.WriteInt64(nci_)) {
1123 return false;
1124 }
1125 if (!parcel.WriteInt32(rsrp_)) {
1126 return false;
1127 }
1128 if (!parcel.WriteInt32(rsrq_)) {
1129 return false;
1130 }
1131 if (!parcel.WriteInt64(timeStamp_)) {
1132 return false;
1133 }
1134 if (!parcel.WriteInt32(signalLevel_)) {
1135 return false;
1136 }
1137 if (!parcel.WriteInt32(signalIntensity_)) {
1138 return false;
1139 }
1140 if (!parcel.WriteBool(isCamped_)) {
1141 return false;
1142 }
1143 return true;
1144 }
1145
Unmarshalling(Parcel & parcel)1146 NrCellInformation *NrCellInformation::Unmarshalling(Parcel &parcel)
1147 {
1148 NrCellInformation *param = new (std::nothrow) NrCellInformation();
1149 if (param == nullptr) {
1150 return nullptr;
1151 }
1152 if (!param->ReadFromParcel(parcel)) {
1153 delete param;
1154 param = nullptr;
1155 }
1156 return param;
1157 }
1158
ReadFromParcel(Parcel & parcel)1159 bool NrCellInformation::ReadFromParcel(Parcel &parcel)
1160 {
1161 std::string readString;
1162 if (!parcel.ReadString(readString)) {
1163 return false;
1164 }
1165 mcc_ = readString;
1166 if (!parcel.ReadString(readString)) {
1167 return false;
1168 }
1169 mnc_ = readString;
1170 if (!ReadIntFromParcel(parcel)) {
1171 return false;
1172 }
1173 uint64_t nrTime = 0;
1174 if (!parcel.ReadUint64(nrTime)) {
1175 return false;
1176 }
1177 int32_t rat;
1178 timeStamp_ = nrTime;
1179 if (!parcel.ReadInt32(rat)) {
1180 return false;
1181 }
1182 signalLevel_ = rat;
1183 int32_t nrSignalIntensity = 0;
1184 if (!parcel.ReadInt32(nrSignalIntensity)) {
1185 return false;
1186 }
1187 signalIntensity_ = nrSignalIntensity;
1188 bool nrTemCamped = false;
1189 if (!parcel.ReadBool(nrTemCamped)) {
1190 return false;
1191 }
1192 isCamped_ = nrTemCamped;
1193 return true;
1194 }
1195
ReadIntFromParcel(Parcel & parcel)1196 bool NrCellInformation::ReadIntFromParcel(Parcel &parcel)
1197 {
1198 int32_t rat;
1199 if (!parcel.ReadInt32(rat)) {
1200 return false;
1201 }
1202 cellId_ = rat;
1203 if (!parcel.ReadInt32(rat)) {
1204 return false;
1205 }
1206 nrArfcn_ = rat;
1207 if (!parcel.ReadInt32(rat)) {
1208 return false;
1209 }
1210 pci_ = rat;
1211 if (!parcel.ReadInt32(rat)) {
1212 return false;
1213 }
1214 tac_ = rat;
1215 int64_t tempNci;
1216 if (!parcel.ReadInt64(tempNci)) {
1217 return false;
1218 }
1219 nci_ = tempNci;
1220 if (!parcel.ReadInt32(rat)) {
1221 return false;
1222 }
1223 rsrp_ = rat;
1224 if (!parcel.ReadInt32(rat)) {
1225 return false;
1226 }
1227 rsrq_ = rat;
1228 return true;
1229 }
1230
GetArfcn() const1231 int32_t NrCellInformation::GetArfcn() const
1232 {
1233 return nrArfcn_;
1234 }
1235
GetPci() const1236 int32_t NrCellInformation::GetPci() const
1237 {
1238 return pci_;
1239 }
1240
GetTac() const1241 int32_t NrCellInformation::GetTac() const
1242 {
1243 return tac_;
1244 }
1245
GetNci() const1246 int64_t NrCellInformation::GetNci() const
1247 {
1248 return nci_;
1249 }
1250
UpdateLocation(int32_t pci,int32_t tac)1251 void NrCellInformation::UpdateLocation(int32_t pci, int32_t tac)
1252 {
1253 pci_ = pci;
1254 tac_ = tac;
1255 timeStamp_ = time(0);
1256 }
1257
ToString() const1258 std::string NrCellInformation::ToString() const
1259 {
1260 int32_t netWorkType = static_cast<int32_t>(NrCellInformation::GetNetworkType());
1261 std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
1262 ",mnc:" + mnc_ + ",earfcn:" + std::to_string(nrArfcn_) + ",cellId:" + std::to_string(cellId_) +
1263 ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
1264 ",signalIntensity:" + std::to_string(signalIntensity_) + ",pci:" + std::to_string(pci_) +
1265 ",tac:" + std::to_string(tac_) + ",nci:" + std::to_string(nci_) + ",rsrp:" + std::to_string(rsrp_) +
1266 ",rsrq:" + std::to_string(rsrq_));
1267 return content;
1268 }
1269 } // namespace Telephony
1270 } // namespace OHOS
1271