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 <ctime>
19 #include <securec.h>
20
21 namespace OHOS {
22 namespace Telephony {
23 const int32_t MNC_INT_MAX = 999;
24 const int32_t MNC_DIGIT_OFFSET = 28;
25 const int32_t MNC_VALID_BIT = 0X0FFFFFFF;
Init(int32_t mcc,int32_t mnc,int32_t cellId)26 void CellInformation::Init(int32_t mcc, int32_t mnc, int32_t cellId)
27 {
28 if (mnc > MNC_INT_MAX) {
29 int mnc_digit = mnc >> MNC_DIGIT_OFFSET;
30 mnc = mnc & MNC_VALID_BIT;
31 char mnc_str[MNC_DIGIT_OFFSET] = {0};
32 char strFormat[MNC_DIGIT_OFFSET] = {0};
33 int size = snprintf_s(strFormat, MNC_DIGIT_OFFSET, MNC_DIGIT_OFFSET - 1, "%s%dd", "%0", mnc_digit);
34 if (size > 0) {
35 size = snprintf_s(mnc_str, mnc_digit + 1, mnc_digit, strFormat, mnc);
36 }
37 if (size > 0) {
38 mnc_ = mnc_str;
39 }
40 } else {
41 mnc_ = std::to_string(mnc);
42 }
43 mcc_ = std::to_string(mcc);
44 cellId_ = cellId;
45 timeStamp_ = time(0);
46 }
47
GetCellId() const48 int32_t CellInformation::GetCellId() const
49 {
50 return cellId_;
51 }
52
GetMcc() const53 std::string CellInformation::GetMcc() const
54 {
55 return mcc_;
56 }
57
GetMnc() const58 std::string CellInformation::GetMnc() const
59 {
60 return mnc_;
61 }
62
GetTimeStamp() const63 uint64_t CellInformation::GetTimeStamp() const
64 {
65 return timeStamp_;
66 }
67
GetSignalLevel() const68 int32_t CellInformation::GetSignalLevel() const
69 {
70 return signalLevel_;
71 }
72
SetSignalLevel(int32_t signalLevel)73 void CellInformation::SetSignalLevel(int32_t signalLevel)
74 {
75 signalLevel_ = signalLevel;
76 timeStamp_ = time(0);
77 }
78
GetIsCamped() const79 bool CellInformation::GetIsCamped() const
80 {
81 return isCamped_;
82 }
83
SetIsCamped(bool isCamped)84 void CellInformation::SetIsCamped(bool isCamped)
85 {
86 isCamped_ = isCamped;
87 timeStamp_ = time(0);
88 }
89
Unmarshalling(Parcel & parcel)90 CellInformation *CellInformation::Unmarshalling(Parcel &parcel)
91 {
92 return nullptr;
93 }
94
SetGsmParam(int32_t bsic,int32_t lac,int32_t arfcn)95 void GsmCellInformation::SetGsmParam(int32_t bsic, int32_t lac, int32_t arfcn)
96 {
97 bsic_ = bsic;
98 lac_ = lac;
99 arfcn_= arfcn;
100 }
101
GsmCellInformation(const GsmCellInformation & gsmCell)102 GsmCellInformation::GsmCellInformation(const GsmCellInformation &gsmCell)
103 {
104 mcc_ = gsmCell.mcc_;
105 mnc_ = gsmCell.mnc_;
106 arfcn_ = gsmCell.arfcn_;
107 cellId_ = gsmCell.cellId_;
108 bsic_ = gsmCell.bsic_;
109 lac_ = gsmCell.lac_;
110 timeStamp_ = gsmCell.timeStamp_;
111 signalLevel_ = gsmCell.signalLevel_;
112 isCamped_ = gsmCell.isCamped_;
113 }
114
operator =(const GsmCellInformation & gsmCell)115 GsmCellInformation &GsmCellInformation::operator=(const GsmCellInformation &gsmCell)
116 {
117 mcc_ = gsmCell.mcc_;
118 mnc_ = gsmCell.mnc_;
119 arfcn_ = gsmCell.arfcn_;
120 cellId_ = gsmCell.cellId_;
121 bsic_ = gsmCell.bsic_;
122 lac_ = gsmCell.lac_;
123 timeStamp_ = gsmCell.timeStamp_;
124 signalLevel_ = gsmCell.signalLevel_;
125 isCamped_ = gsmCell.isCamped_;
126 return *this;
127 }
128
operator ==(const GsmCellInformation & other) const129 bool GsmCellInformation::operator==(const GsmCellInformation &other) const
130 {
131 return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
132 arfcn_ == other.arfcn_ && cellId_ == other.cellId_ &&
133 bsic_ == other.bsic_ && lac_ == other.lac_ &&
134 signalLevel_ == other.signalLevel_ &&
135 isCamped_ == other.isCamped_;
136 }
137
GetNetworkType() const138 CellInformation::CellType GsmCellInformation::GetNetworkType() const
139 {
140 return CellType::CELL_TYPE_GSM;
141 }
142
GetArfcn() const143 int32_t GsmCellInformation::GetArfcn() const
144 {
145 return arfcn_;
146 }
147
ToString() const148 std::string GsmCellInformation::ToString() const
149 {
150 int32_t netWorkType = static_cast<int32_t>(GsmCellInformation::GetNetworkType());
151 std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
152 ",mnc:" + mnc_ + ",arfcn:" + std::to_string(arfcn_) + ",cellId:" + std::to_string(cellId_) +
153 ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
154 ",bsic:" + std::to_string(bsic_) + ",lac:" + std::to_string(lac_));
155 return content;
156 }
157
Marshalling(Parcel & parcel) const158 bool GsmCellInformation::Marshalling(Parcel &parcel) const
159 {
160 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_GSM))) {
161 return false;
162 }
163 if (!parcel.WriteString(mcc_)) {
164 return false;
165 }
166 if (!parcel.WriteString(mnc_)) {
167 return false;
168 }
169 if (!parcel.WriteInt32(arfcn_)) {
170 return false;
171 }
172 if (!parcel.WriteInt32(cellId_)) {
173 return false;
174 }
175 if (!parcel.WriteInt32(bsic_)) {
176 return false;
177 }
178 if (!parcel.WriteInt32(lac_)) {
179 return false;
180 }
181 if (!parcel.WriteInt64(timeStamp_)) {
182 return false;
183 }
184 if (!parcel.WriteInt32(signalLevel_)) {
185 return false;
186 }
187 if (!parcel.WriteBool(isCamped_)) {
188 return false;
189 }
190 return true;
191 }
192
Unmarshalling(Parcel & parcel)193 GsmCellInformation *GsmCellInformation::Unmarshalling(Parcel &parcel)
194 {
195 GsmCellInformation *param = new (std::nothrow) GsmCellInformation();
196 if (param == nullptr) {
197 return nullptr;
198 }
199 if (!param->ReadFromParcel(parcel)) {
200 delete param;
201 param = nullptr;
202 }
203 return param;
204 }
205
ReadFromParcel(Parcel & parcel)206 bool GsmCellInformation::ReadFromParcel(Parcel &parcel)
207 {
208 mcc_ = parcel.ReadString();
209 mnc_ = parcel.ReadString();
210 arfcn_ = parcel.ReadInt32();
211 cellId_ = parcel.ReadInt32();
212 bsic_ = parcel.ReadInt32();
213 lac_ = parcel.ReadInt32();
214 timeStamp_ = parcel.ReadInt64();
215 signalLevel_ = parcel.ReadInt32();
216 isCamped_ = parcel.ReadBool();
217
218 return true;
219 }
220
GetLac() const221 int32_t GsmCellInformation::GetLac() const
222 {
223 return lac_;
224 }
225
GetBsic() const226 int32_t GsmCellInformation::GetBsic() const
227 {
228 return bsic_;
229 }
230
UpdateLocation(int32_t cellId,int32_t lac)231 void GsmCellInformation::UpdateLocation(int32_t cellId, int32_t lac)
232 {
233 cellId_ = cellId;
234 lac_ = lac;
235 timeStamp_ = time(0);
236 }
237
SetLteParam(int32_t pci,int32_t tac,int32_t arfcn)238 void LteCellInformation::SetLteParam(int32_t pci, int32_t tac, int32_t arfcn)
239 {
240 pci_ = pci;
241 tac_ = tac;
242 earfcn_= arfcn;
243 }
244
LteCellInformation(const LteCellInformation & lteCell)245 LteCellInformation::LteCellInformation(const LteCellInformation <eCell)
246 {
247 mcc_ = lteCell.mcc_;
248 mnc_ = lteCell.mnc_;
249 earfcn_ = lteCell.earfcn_;
250 cellId_ = lteCell.cellId_;
251 pci_ = lteCell.pci_;
252 tac_ = lteCell.tac_;
253 timeStamp_ = lteCell.timeStamp_;
254 signalLevel_ = lteCell.signalLevel_;
255 isCamped_ = lteCell.isCamped_;
256 }
257
operator =(const LteCellInformation & lteCell)258 LteCellInformation &LteCellInformation::operator=(const LteCellInformation <eCell)
259 {
260 mcc_ = lteCell.mcc_;
261 mnc_ = lteCell.mnc_;
262 earfcn_ = lteCell.earfcn_;
263 cellId_ = lteCell.cellId_;
264 pci_ = lteCell.pci_;
265 tac_ = lteCell.tac_;
266 timeStamp_ = lteCell.timeStamp_;
267 signalLevel_ = lteCell.signalLevel_;
268 isCamped_ = lteCell.isCamped_;
269 return *this;
270 }
271
operator ==(const LteCellInformation & other) const272 bool LteCellInformation::operator==(const LteCellInformation &other) const
273 {
274 return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
275 earfcn_ == other.earfcn_ && cellId_ == other.cellId_ &&
276 pci_ == other.pci_ && tac_ == other.tac_ &&
277 signalLevel_ == other.signalLevel_ &&
278 isCamped_ == other.isCamped_;
279 }
280
GetNetworkType() const281 CellInformation::CellType LteCellInformation::GetNetworkType() const
282 {
283 return CellType::CELL_TYPE_LTE;
284 }
285
GetArfcn() const286 int32_t LteCellInformation::GetArfcn() const
287 {
288 return earfcn_;
289 }
290
Marshalling(Parcel & parcel) const291 bool LteCellInformation::Marshalling(Parcel &parcel) const
292 {
293 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_LTE))) {
294 return false;
295 }
296 if (!parcel.WriteString(mcc_)) {
297 return false;
298 }
299 if (!parcel.WriteString(mnc_)) {
300 return false;
301 }
302 if (!parcel.WriteInt32(earfcn_)) {
303 return false;
304 }
305 if (!parcel.WriteInt32(cellId_)) {
306 return false;
307 }
308 if (!parcel.WriteInt32(pci_)) {
309 return false;
310 }
311 if (!parcel.WriteInt32(tac_)) {
312 return false;
313 }
314 if (!parcel.WriteInt64(timeStamp_)) {
315 return false;
316 }
317 if (!parcel.WriteInt32(signalLevel_)) {
318 return false;
319 }
320 if (!parcel.WriteBool(isCamped_)) {
321 return false;
322 }
323 return true;
324 }
325
Unmarshalling(Parcel & parcel)326 LteCellInformation *LteCellInformation::Unmarshalling(Parcel &parcel)
327 {
328 LteCellInformation *param = new (std::nothrow) LteCellInformation();
329 if (param == nullptr) {
330 return nullptr;
331 }
332 if (!param->ReadFromParcel(parcel)) {
333 delete param;
334 param = nullptr;
335 }
336 return param;
337 }
338
ReadFromParcel(Parcel & parcel)339 bool LteCellInformation::ReadFromParcel(Parcel &parcel)
340 {
341 mcc_ = parcel.ReadString();
342 mnc_ = parcel.ReadString();
343 earfcn_ = parcel.ReadInt32();
344 cellId_ = parcel.ReadInt32();
345 pci_ = parcel.ReadInt32();
346 tac_ = parcel.ReadInt32();
347 timeStamp_ = parcel.ReadInt64();
348 signalLevel_ = parcel.ReadInt32();
349 isCamped_ = parcel.ReadBool();
350 return true;
351 }
352
GetPci() const353 int32_t LteCellInformation::GetPci() const
354 {
355 return pci_;
356 }
357
GetTac() const358 int32_t LteCellInformation::GetTac() const
359 {
360 return tac_;
361 }
362
UpdateLocation(int32_t cellId,int32_t tac)363 void LteCellInformation::UpdateLocation(int32_t cellId, int32_t tac)
364 {
365 cellId_ = cellId;
366 tac_ = tac;
367 timeStamp_ = time(0);
368 }
369
ToString() const370 std::string LteCellInformation::ToString() const
371 {
372 int32_t netWorkType = static_cast<int32_t>(LteCellInformation::GetNetworkType());
373 std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
374 ",mnc:" + mnc_ + ",earfcn:" + std::to_string(earfcn_) + ",cellId:" + std::to_string(cellId_) +
375 ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
376 ",pci:" + std::to_string(pci_) + ",tac:" + std::to_string(tac_));
377 return content;
378 }
379
SetWcdmaParam(int32_t psc,int32_t lac,int32_t arfcn)380 void WcdmaCellInformation::SetWcdmaParam(int32_t psc, int32_t lac, int32_t arfcn)
381 {
382 psc_ = psc;
383 lac_ = lac;
384 uarfcn_= arfcn;
385 }
386
WcdmaCellInformation(const WcdmaCellInformation & wcdmaCell)387 WcdmaCellInformation::WcdmaCellInformation(const WcdmaCellInformation &wcdmaCell)
388 {
389 mcc_ = wcdmaCell.mcc_;
390 mnc_ = wcdmaCell.mnc_;
391 uarfcn_ = wcdmaCell.uarfcn_;
392 cellId_ = wcdmaCell.cellId_;
393 psc_ = wcdmaCell.psc_;
394 lac_ = wcdmaCell.lac_;
395 timeStamp_ = wcdmaCell.timeStamp_;
396 signalLevel_ = wcdmaCell.signalLevel_;
397 isCamped_ = wcdmaCell.isCamped_;
398 }
399
operator =(const WcdmaCellInformation & wcdmaCell)400 WcdmaCellInformation &WcdmaCellInformation::operator=(const WcdmaCellInformation &wcdmaCell)
401 {
402 mcc_ = wcdmaCell.mcc_;
403 mnc_ = wcdmaCell.mnc_;
404 uarfcn_ = wcdmaCell.uarfcn_;
405 cellId_ = wcdmaCell.cellId_;
406 psc_ = wcdmaCell.psc_;
407 lac_ = wcdmaCell.lac_;
408 timeStamp_ = wcdmaCell.timeStamp_;
409 signalLevel_ = wcdmaCell.signalLevel_;
410 isCamped_ = wcdmaCell.isCamped_;
411 return *this;
412 }
413
operator ==(const WcdmaCellInformation & other) const414 bool WcdmaCellInformation::operator==(const WcdmaCellInformation &other) const
415 {
416 return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
417 uarfcn_ == other.uarfcn_ && cellId_ == other.cellId_ &&
418 psc_ == other.psc_ && lac_ == other.lac_ &&
419 signalLevel_ == other.signalLevel_ &&
420 isCamped_ == other.isCamped_;
421 }
422
GetNetworkType() const423 CellInformation::CellType WcdmaCellInformation::GetNetworkType() const
424 {
425 return CellType::CELL_TYPE_WCDMA;
426 }
427
GetArfcn() const428 int32_t WcdmaCellInformation::GetArfcn() const
429 {
430 return uarfcn_;
431 }
432
Marshalling(Parcel & parcel) const433 bool WcdmaCellInformation::Marshalling(Parcel &parcel) const
434 {
435 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_WCDMA))) {
436 return false;
437 }
438 if (!parcel.WriteString(mcc_)) {
439 return false;
440 }
441 if (!parcel.WriteString(mnc_)) {
442 return false;
443 }
444 if (!parcel.WriteInt32(uarfcn_)) {
445 return false;
446 }
447 if (!parcel.WriteInt32(cellId_)) {
448 return false;
449 }
450 if (!parcel.WriteInt32(psc_)) {
451 return false;
452 }
453 if (!parcel.WriteInt32(lac_)) {
454 return false;
455 }
456 if (!parcel.WriteInt64(timeStamp_)) {
457 return false;
458 }
459 if (!parcel.WriteInt32(signalLevel_)) {
460 return false;
461 }
462 if (!parcel.WriteBool(isCamped_)) {
463 return false;
464 }
465 return true;
466 }
467
Unmarshalling(Parcel & parcel)468 WcdmaCellInformation *WcdmaCellInformation::Unmarshalling(Parcel &parcel)
469 {
470 WcdmaCellInformation *param = new (std::nothrow) WcdmaCellInformation();
471 if (param == nullptr) {
472 return nullptr;
473 }
474 if (!param->ReadFromParcel(parcel)) {
475 delete param;
476 param = nullptr;
477 }
478 return param;
479 }
480
ReadFromParcel(Parcel & parcel)481 bool WcdmaCellInformation::ReadFromParcel(Parcel &parcel)
482 {
483 mcc_ = parcel.ReadString();
484 mnc_ = parcel.ReadString();
485 uarfcn_ = parcel.ReadInt32();
486 cellId_ = parcel.ReadInt32();
487 psc_ = parcel.ReadInt32();
488 lac_ = parcel.ReadInt32();
489 timeStamp_ = parcel.ReadInt64();
490 signalLevel_ = parcel.ReadInt32();
491 isCamped_ = parcel.ReadBool();
492 return true;
493 }
494
GetPsc() const495 int32_t WcdmaCellInformation::GetPsc() const
496 {
497 return psc_;
498 }
499
GetLac() const500 int32_t WcdmaCellInformation::GetLac() const
501 {
502 return lac_;
503 }
504
UpdateLocation(int32_t cellId,int32_t lac)505 void WcdmaCellInformation::UpdateLocation(int32_t cellId, int32_t lac)
506 {
507 cellId_ = cellId;
508 lac_ = lac;
509 timeStamp_ = time(0);
510 }
511
ToString() const512 std::string WcdmaCellInformation::ToString() const
513 {
514 int32_t netWorkType = static_cast<int32_t>(WcdmaCellInformation::GetNetworkType());
515 std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
516 ",mnc:" + mnc_ + ",uarfcn:" + std::to_string(uarfcn_) + ",cellId:" + std::to_string(cellId_) +
517 ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
518 ",psc:" + std::to_string(psc_) + ",lac:" + std::to_string(lac_));
519 return content;
520 }
521
SetTdscdmaParam(int32_t cpid,int32_t lac,int32_t arfcn)522 void TdscdmaCellInformation::SetTdscdmaParam(int32_t cpid, int32_t lac, int32_t arfcn)
523 {
524 cpid_ = cpid;
525 lac_ = lac;
526 uarfcn_= arfcn;
527 }
528
TdscdmaCellInformation(const TdscdmaCellInformation & tdscdmaCell)529 TdscdmaCellInformation::TdscdmaCellInformation(const TdscdmaCellInformation &tdscdmaCell)
530 {
531 mcc_ = tdscdmaCell.mcc_;
532 mnc_ = tdscdmaCell.mnc_;
533 uarfcn_ = tdscdmaCell.uarfcn_;
534 cellId_ = tdscdmaCell.cellId_;
535 cpid_ = tdscdmaCell.cpid_;
536 lac_ = tdscdmaCell.lac_;
537 timeStamp_ = tdscdmaCell.timeStamp_;
538 signalLevel_ = tdscdmaCell.signalLevel_;
539 isCamped_ = tdscdmaCell.isCamped_;
540 }
541
operator =(const TdscdmaCellInformation & tdscdmaCell)542 TdscdmaCellInformation &TdscdmaCellInformation::operator=(const TdscdmaCellInformation &tdscdmaCell)
543 {
544 mcc_ = tdscdmaCell.mcc_;
545 mnc_ = tdscdmaCell.mnc_;
546 uarfcn_ = tdscdmaCell.uarfcn_;
547 cellId_ = tdscdmaCell.cellId_;
548 cpid_ = tdscdmaCell.cpid_;
549 lac_ = tdscdmaCell.lac_;
550 timeStamp_ = tdscdmaCell.timeStamp_;
551 signalLevel_ = tdscdmaCell.signalLevel_;
552 isCamped_ = tdscdmaCell.isCamped_;
553 return *this;
554 }
555
operator ==(const TdscdmaCellInformation & other) const556 bool TdscdmaCellInformation::operator==(const TdscdmaCellInformation &other) const
557 {
558 return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
559 uarfcn_ == other.uarfcn_ && cellId_ == other.cellId_ &&
560 cpid_ == other.cpid_ && lac_ == other.lac_ &&
561 signalLevel_ == other.signalLevel_ &&
562 isCamped_ == other.isCamped_;
563 }
564
GetNetworkType() const565 CellInformation::CellType TdscdmaCellInformation::GetNetworkType() const
566 {
567 return CellType::CELL_TYPE_TDSCDMA;
568 }
569
GetArfcn() const570 int32_t TdscdmaCellInformation::GetArfcn() const
571 {
572 return uarfcn_;
573 }
574
Marshalling(Parcel & parcel) const575 bool TdscdmaCellInformation::Marshalling(Parcel &parcel) const
576 {
577 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_TDSCDMA))) {
578 return false;
579 }
580 if (!parcel.WriteString(mcc_)) {
581 return false;
582 }
583 if (!parcel.WriteString(mnc_)) {
584 return false;
585 }
586 if (!parcel.WriteInt32(uarfcn_)) {
587 return false;
588 }
589 if (!parcel.WriteInt32(cellId_)) {
590 return false;
591 }
592 if (!parcel.WriteInt32(cpid_)) {
593 return false;
594 }
595 if (!parcel.WriteInt32(lac_)) {
596 return false;
597 }
598 if (!parcel.WriteInt64(timeStamp_)) {
599 return false;
600 }
601 if (!parcel.WriteInt32(signalLevel_)) {
602 return false;
603 }
604 if (!parcel.WriteBool(isCamped_)) {
605 return false;
606 }
607 return true;
608 }
609
Unmarshalling(Parcel & parcel)610 TdscdmaCellInformation *TdscdmaCellInformation::Unmarshalling(Parcel &parcel)
611 {
612 TdscdmaCellInformation *param = new (std::nothrow) TdscdmaCellInformation();
613 if (param == nullptr) {
614 return nullptr;
615 }
616 if (!param->ReadFromParcel(parcel)) {
617 delete param;
618 param = nullptr;
619 }
620 return param;
621 }
622
ReadFromParcel(Parcel & parcel)623 bool TdscdmaCellInformation::ReadFromParcel(Parcel &parcel)
624 {
625 mcc_ = parcel.ReadString();
626 mnc_ = parcel.ReadString();
627 uarfcn_ = parcel.ReadInt32();
628 cellId_ = parcel.ReadInt32();
629 cpid_ = parcel.ReadInt32();
630 lac_ = parcel.ReadInt32();
631 timeStamp_ = parcel.ReadInt64();
632 signalLevel_ = parcel.ReadInt32();
633 isCamped_ = parcel.ReadBool();
634 return true;
635 }
636
GetCpid() const637 int32_t TdscdmaCellInformation::GetCpid() const
638 {
639 return cpid_;
640 }
641
GetLac() const642 int32_t TdscdmaCellInformation::GetLac() const
643 {
644 return lac_;
645 }
646
UpdateLocation(int32_t cellId,int32_t lac)647 void TdscdmaCellInformation::UpdateLocation(int32_t cellId, int32_t lac)
648 {
649 cellId_ = cellId;
650 lac_ = lac;
651 timeStamp_ = time(0);
652 }
653
ToString() const654 std::string TdscdmaCellInformation::ToString() const
655 {
656 int32_t netWorkType = static_cast<int32_t>(TdscdmaCellInformation::GetNetworkType());
657 std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
658 ",mnc:" + mnc_ + ",uarfcn:" + std::to_string(uarfcn_) + ",cellId:" + std::to_string(cellId_) +
659 ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
660 ",cpid:" + std::to_string(cpid_) + ",lac:" + std::to_string(lac_));
661 return content;
662 }
663
SetCdmaParam(int32_t baseId,int32_t latitude,int32_t longitude,int32_t nid,int32_t sid)664 void CdmaCellInformation::SetCdmaParam(int32_t baseId, int32_t latitude, int32_t longitude, int32_t nid, int32_t sid)
665 {
666 baseId_ = baseId;
667 latitude_ = latitude;
668 longitude_= longitude;
669 nid_ = nid;
670 sid_= sid;
671 }
672
CdmaCellInformation(const CdmaCellInformation & cdmaCell)673 CdmaCellInformation::CdmaCellInformation(const CdmaCellInformation &cdmaCell)
674 {
675 baseId_ = cdmaCell.baseId_;
676 latitude_ = cdmaCell.latitude_;
677 longitude_= cdmaCell.longitude_;
678 nid_ = cdmaCell.nid_;
679 sid_= cdmaCell.sid_;
680 timeStamp_ = cdmaCell.timeStamp_;
681 signalLevel_ = cdmaCell.signalLevel_;
682 isCamped_ = cdmaCell.isCamped_;
683 }
684
operator =(const CdmaCellInformation & cdmaCell)685 CdmaCellInformation &CdmaCellInformation::operator=(const CdmaCellInformation &cdmaCell)
686 {
687 baseId_ = cdmaCell.baseId_;
688 latitude_ = cdmaCell.latitude_;
689 longitude_= cdmaCell.longitude_;
690 nid_ = cdmaCell.nid_;
691 sid_= cdmaCell.sid_;
692 timeStamp_ = cdmaCell.timeStamp_;
693 signalLevel_ = cdmaCell.signalLevel_;
694 isCamped_ = cdmaCell.isCamped_;
695 return *this;
696 }
697
operator ==(const CdmaCellInformation & other) const698 bool CdmaCellInformation::operator==(const CdmaCellInformation &other) const
699 {
700 return baseId_ == other.baseId_ && latitude_ == other.latitude_ &&
701 longitude_ == other.longitude_ && nid_ == other.nid_ &&
702 sid_ == other.sid_ &&
703 signalLevel_ == other.signalLevel_ && isCamped_ == other.isCamped_;
704 }
705
GetNetworkType() const706 CellInformation::CellType CdmaCellInformation::GetNetworkType() const
707 {
708 return CellType::CELL_TYPE_CDMA;
709 }
710
Marshalling(Parcel & parcel) const711 bool CdmaCellInformation::Marshalling(Parcel &parcel) const
712 {
713 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_CDMA))) {
714 return false;
715 }
716 if (!parcel.WriteInt32(baseId_)) {
717 return false;
718 }
719 if (!parcel.WriteInt32(latitude_)) {
720 return false;
721 }
722 if (!parcel.WriteInt32(longitude_)) {
723 return false;
724 }
725 if (!parcel.WriteInt32(nid_)) {
726 return false;
727 }
728 if (!parcel.WriteInt32(sid_)) {
729 return false;
730 }
731 if (!parcel.WriteInt64(timeStamp_)) {
732 return false;
733 }
734 if (!parcel.WriteInt32(signalLevel_)) {
735 return false;
736 }
737 if (!parcel.WriteBool(isCamped_)) {
738 return false;
739 }
740 return true;
741 }
742
Unmarshalling(Parcel & parcel)743 CdmaCellInformation *CdmaCellInformation::Unmarshalling(Parcel &parcel)
744 {
745 CdmaCellInformation *param = new (std::nothrow) CdmaCellInformation();
746 if (param == nullptr) {
747 return nullptr;
748 }
749 if (!param->ReadFromParcel(parcel)) {
750 delete param;
751 param = nullptr;
752 }
753 return param;
754 }
755
ReadFromParcel(Parcel & parcel)756 bool CdmaCellInformation::ReadFromParcel(Parcel &parcel)
757 {
758 baseId_ = parcel.ReadInt32();
759 latitude_ = parcel.ReadInt32();
760 longitude_ = parcel.ReadInt32();
761 nid_ = parcel.ReadInt32();
762 sid_ = parcel.ReadInt32();
763 timeStamp_ = parcel.ReadInt64();
764 signalLevel_ = parcel.ReadInt32();
765 isCamped_ = parcel.ReadBool();
766 return true;
767 }
768
GetBaseId() const769 int32_t CdmaCellInformation::GetBaseId() const
770 {
771 return baseId_;
772 }
773
GetLatitude() const774 int32_t CdmaCellInformation::GetLatitude() const
775 {
776 return latitude_;
777 }
778
GetLongitude() const779 int32_t CdmaCellInformation::GetLongitude() const
780 {
781 return longitude_;
782 }
783
GetNid() const784 int32_t CdmaCellInformation::GetNid() const
785 {
786 return nid_;
787 }
788
GetSid() const789 int32_t CdmaCellInformation::GetSid() const
790 {
791 return sid_;
792 }
793
UpdateLocation(int32_t baseId,int32_t latitude,int32_t longitude)794 void CdmaCellInformation::UpdateLocation(int32_t baseId, int32_t latitude, int32_t longitude)
795 {
796 baseId_ = baseId;
797 latitude_ = latitude;
798 longitude_ = longitude;
799 timeStamp_ = time(0);
800 }
801
ToString() const802 std::string CdmaCellInformation::ToString() const
803 {
804 int32_t netWorkType = static_cast<int32_t>(CdmaCellInformation::GetNetworkType());
805 std::string content("netWorkType:" + std::to_string(netWorkType) + ",baseId:" + std::to_string(baseId_) +
806 ",latitude:" + std::to_string(latitude_) + ",longitude:" + std::to_string(longitude_) +
807 ",nid:" + std::to_string(nid_) + ",timeStamp:" + std::to_string(timeStamp_) +
808 ",signalLevel:" + std::to_string(signalLevel_) + ",sid:" + std::to_string(sid_));
809 return content;
810 }
811
SetNrParam(int32_t nrArfcn,int32_t pci,int32_t tac,int64_t nci)812 void NrCellInformation::SetNrParam(int32_t nrArfcn, int32_t pci, int32_t tac, int64_t nci)
813 {
814 nrArfcn_ = nrArfcn;
815 pci_ = pci;
816 tac_= tac;
817 nci_ = nci;
818 }
819
NrCellInformation(const NrCellInformation & nrCell)820 NrCellInformation::NrCellInformation(const NrCellInformation &nrCell)
821 {
822 mcc_ = nrCell.mcc_;
823 mnc_ = nrCell.mnc_;
824 cellId_ = nrCell.cellId_;
825 nrArfcn_ = nrCell.nrArfcn_;
826 pci_ = nrCell.pci_;
827 tac_ = nrCell.tac_;
828 nci_ = nrCell.nci_;
829 timeStamp_ = nrCell.timeStamp_;
830 signalLevel_ = nrCell.signalLevel_;
831 isCamped_ = nrCell.isCamped_;
832 }
833
operator =(const NrCellInformation & nrCell)834 NrCellInformation &NrCellInformation::operator=(const NrCellInformation &nrCell)
835 {
836 mcc_ = nrCell.mcc_;
837 mnc_ = nrCell.mnc_;
838 cellId_ = nrCell.cellId_;
839 nrArfcn_ = nrCell.nrArfcn_;
840 pci_ = nrCell.pci_;
841 tac_ = nrCell.tac_;
842 nci_ = nrCell.nci_;
843 timeStamp_ = nrCell.timeStamp_;
844 signalLevel_ = nrCell.signalLevel_;
845 isCamped_ = nrCell.isCamped_;
846 return *this;
847 }
848
operator ==(const NrCellInformation & other) const849 bool NrCellInformation::operator==(const NrCellInformation &other) const
850 {
851 return mcc_ == other.mcc_ && mnc_ == other.mnc_ &&
852 cellId_ == other.cellId_ && nrArfcn_ == other.nrArfcn_ &&
853 pci_ == other.pci_ && tac_ == other.tac_ && nci_ == other.nci_ &&
854 signalLevel_ == other.signalLevel_ &&
855 isCamped_ == other.isCamped_;
856 }
857
GetNetworkType() const858 CellInformation::CellType NrCellInformation::GetNetworkType() const
859 {
860 return CellType::CELL_TYPE_NR;
861 }
862
Marshalling(Parcel & parcel) const863 bool NrCellInformation::Marshalling(Parcel &parcel) const
864 {
865 if (!parcel.WriteInt32(static_cast<int32_t>(CellInformation::CellType::CELL_TYPE_NR))) {
866 return false;
867 }
868 if (!parcel.WriteString(mcc_)) {
869 return false;
870 }
871 if (!parcel.WriteString(mnc_)) {
872 return false;
873 }
874 if (!parcel.WriteInt32(cellId_)) {
875 return false;
876 }
877 if (!parcel.WriteInt32(nrArfcn_)) {
878 return false;
879 }
880 if (!parcel.WriteInt32(pci_)) {
881 return false;
882 }
883 if (!parcel.WriteInt32(tac_)) {
884 return false;
885 }
886 if (!parcel.WriteInt64(nci_)) {
887 return false;
888 }
889 if (!parcel.WriteInt64(timeStamp_)) {
890 return false;
891 }
892 if (!parcel.WriteInt32(signalLevel_)) {
893 return false;
894 }
895 if (!parcel.WriteBool(isCamped_)) {
896 return false;
897 }
898 return true;
899 }
900
Unmarshalling(Parcel & parcel)901 NrCellInformation *NrCellInformation::Unmarshalling(Parcel &parcel)
902 {
903 NrCellInformation *param = new (std::nothrow) NrCellInformation();
904 if (param == nullptr) {
905 return nullptr;
906 }
907 if (!param->ReadFromParcel(parcel)) {
908 delete param;
909 param = nullptr;
910 }
911 return param;
912 }
913
ReadFromParcel(Parcel & parcel)914 bool NrCellInformation::ReadFromParcel(Parcel &parcel)
915 {
916 mcc_ = parcel.ReadString();
917 mnc_ = parcel.ReadString();
918 cellId_ = parcel.ReadInt32();
919 nrArfcn_ = parcel.ReadInt32();
920 pci_ = parcel.ReadInt32();
921 tac_ = parcel.ReadInt32();
922 nci_ = parcel.ReadInt64();
923 timeStamp_ = parcel.ReadInt64();
924 signalLevel_ = parcel.ReadInt32();
925 isCamped_ = parcel.ReadBool();
926 return true;
927 }
928
GetArfcn() const929 int32_t NrCellInformation::GetArfcn() const
930 {
931 return nrArfcn_;
932 }
933
GetPci() const934 int32_t NrCellInformation::GetPci() const
935 {
936 return pci_;
937 }
938
GetTac() const939 int32_t NrCellInformation::GetTac() const
940 {
941 return tac_;
942 }
943
GetNci() const944 int64_t NrCellInformation::GetNci() const
945 {
946 return nci_;
947 }
948
UpdateLocation(int32_t pci,int32_t tac)949 void NrCellInformation::UpdateLocation(int32_t pci, int32_t tac)
950 {
951 pci_ = pci;
952 tac_ = tac;
953 timeStamp_ = time(0);
954 }
955
ToString() const956 std::string NrCellInformation::ToString() const
957 {
958 int32_t netWorkType = static_cast<int32_t>(NrCellInformation::GetNetworkType());
959 std::string content("netWorkType:" + std::to_string(netWorkType) + ",mcc:" + mcc_ +
960 ",mnc:" + mnc_ + ",earfcn:" + std::to_string(nrArfcn_) + ",cellId:" + std::to_string(cellId_) +
961 ",timeStamp:" + std::to_string(timeStamp_) + ",signalLevel:" + std::to_string(signalLevel_) +
962 ",pci:" + std::to_string(pci_) + ",tac:" + std::to_string(tac_) + ",nci:" + std::to_string(nci_));
963 return content;
964 }
965 } // namespace Telephony
966 } // namespace OHOS