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 "signal_information.h"
17
18 #include <string_ex.h>
19 #include "telephony_log_wrapper.h"
20
21 namespace OHOS {
22 namespace Telephony {
23 constexpr int32_t SIGNAL_RSSI_MAXIMUM = -1;
24 constexpr int32_t SIGNAL_INTENSITY_INVALID = 0;
25 constexpr int32_t SIGNAL_LEVEL_INVALID = 0;
26 constexpr int32_t SIGNAL_FIVE_BARS = 5;
27 constexpr int32_t SIGNAL_FOUR_BARS = 4;
28 const int32_t *GSM_SIGNAL_THRESHOLD = SignalInformation::GSM_SIGNAL_THRESHOLD_5BAR;
29 const int32_t *CDMA_SIGNAL_THRESHOLD = SignalInformation::CDMA_SIGNAL_THRESHOLD_5BAR;
30 const int32_t *LTE_SIGNAL_THRESHOLD = SignalInformation::LTE_SIGNAL_THRESHOLD_5BAR;
31 const int32_t *WCDMA_SIGNAL_THRESHOLD = SignalInformation::WCDMA_SIGNAL_THRESHOLD_5BAR;
32 const int32_t *TD_SCDMA_SIGNAL_THRESHOLD = SignalInformation::TD_SCDMA_SIGNAL_THRESHOLD_5BAR;
33 const int32_t *NR_SIGNAL_THRESHOLD = SignalInformation::NR_SIGNAL_THRESHOLD_5BAR;
34 int32_t SignalInformation::signalBar_ = SIGNAL_FIVE_BARS;
35
SignalInformation()36 SignalInformation::SignalInformation()
37 {
38 InitSignalBar();
39 }
40
InitSignalBar(const int32_t bar)41 void SignalInformation::InitSignalBar(const int32_t bar)
42 {
43 if (bar == SIGNAL_FOUR_BARS) {
44 GSM_SIGNAL_THRESHOLD = SignalInformation::GSM_SIGNAL_THRESHOLD_4BAR;
45 CDMA_SIGNAL_THRESHOLD = SignalInformation::CDMA_SIGNAL_THRESHOLD_4BAR;
46 LTE_SIGNAL_THRESHOLD = SignalInformation::LTE_SIGNAL_THRESHOLD_4BAR;
47 WCDMA_SIGNAL_THRESHOLD = SignalInformation::WCDMA_SIGNAL_THRESHOLD_4BAR;
48 TD_SCDMA_SIGNAL_THRESHOLD = SignalInformation::TD_SCDMA_SIGNAL_THRESHOLD_4BAR;
49 NR_SIGNAL_THRESHOLD = SignalInformation::NR_SIGNAL_THRESHOLD_4BAR;
50 signalBar_ = SIGNAL_FOUR_BARS;
51 } else {
52 GSM_SIGNAL_THRESHOLD = SignalInformation::GSM_SIGNAL_THRESHOLD_5BAR;
53 CDMA_SIGNAL_THRESHOLD = SignalInformation::CDMA_SIGNAL_THRESHOLD_5BAR;
54 LTE_SIGNAL_THRESHOLD = SignalInformation::LTE_SIGNAL_THRESHOLD_5BAR;
55 WCDMA_SIGNAL_THRESHOLD = SignalInformation::WCDMA_SIGNAL_THRESHOLD_5BAR;
56 TD_SCDMA_SIGNAL_THRESHOLD = SignalInformation::TD_SCDMA_SIGNAL_THRESHOLD_5BAR;
57 NR_SIGNAL_THRESHOLD = SignalInformation::NR_SIGNAL_THRESHOLD_5BAR;
58 signalBar_ = SIGNAL_FIVE_BARS;
59 }
60 }
61
Unmarshalling(Parcel & parcel)62 std::unique_ptr<SignalInformation> SignalInformation::Unmarshalling(Parcel &parcel)
63 {
64 return nullptr;
65 }
66
operator ==(const GsmSignalInformation & gsm) const67 bool GsmSignalInformation::operator==(const GsmSignalInformation &gsm) const
68 {
69 return gsmRxlev_ == gsm.gsmRxlev_ && gsmBer_ == gsm.gsmBer_;
70 }
71
SetValue(const int32_t gsmRssi,const int32_t gsmBer)72 void GsmSignalInformation::SetValue(const int32_t gsmRssi, const int32_t gsmBer)
73 {
74 gsmRxlev_ = gsmRssi;
75 gsmBer_ = gsmBer;
76 }
77
GetRssi() const78 int32_t GsmSignalInformation::GetRssi() const
79 {
80 return gsmRxlev_;
81 }
82
GetGsmBer() const83 int32_t GsmSignalInformation::GetGsmBer() const
84 {
85 return gsmBer_;
86 }
87
GetSignalIntensity() const88 int32_t GsmSignalInformation::GetSignalIntensity() const
89 {
90 int32_t signalIntensity = SIGNAL_INTENSITY_INVALID;
91
92 if (ValidateGsmValue()) {
93 signalIntensity = GetRssi();
94 } else {
95 TELEPHONY_LOGE("GsmSignalInformation::GetSignalIntensity Value is Invalid.");
96 }
97
98 return signalIntensity;
99 }
100
GetSignalLevel() const101 int32_t GsmSignalInformation::GetSignalLevel() const
102 {
103 int32_t level = SIGNAL_LEVEL_INVALID;
104 int32_t gsmRxlev = GetRssi();
105 if (ValidateGsmValue()) {
106 // Reference: TS 27.007 section 8.69
107 for (int32_t i = signalBar_; i >= 0; --i) {
108 if (gsmRxlev >= GSM_SIGNAL_THRESHOLD[i]) {
109 level = i;
110 break;
111 }
112 }
113 } else {
114 TELEPHONY_LOGE("GsmSignalInformation::GetSignalLevel Value is Invalid.");
115 }
116 return level;
117 }
118
GetNetworkType() const119 SignalInformation::NetworkType GsmSignalInformation::GetNetworkType() const
120 {
121 return SignalInformation::NetworkType::GSM;
122 }
123
ToString() const124 std::string GsmSignalInformation::ToString() const
125 {
126 int32_t netWorkType = static_cast<int32_t>(GsmSignalInformation::GetNetworkType());
127 std::string content("networkType:" + std::to_string(netWorkType) + ",gsmRxlev:" + std::to_string(gsmRxlev_) +
128 ",signalLevel:" + std::to_string(GsmSignalInformation::GetSignalLevel()) +
129 ",gsmBer:" + std::to_string(gsmBer_));
130 return content;
131 }
132
NewInstance() const133 sptr<SignalInformation> GsmSignalInformation::NewInstance() const
134 {
135 std::unique_ptr<GsmSignalInformation> gsm = std::make_unique<GsmSignalInformation>();
136 if (gsm == nullptr) {
137 return nullptr;
138 }
139 gsm->SetValue(this->gsmRxlev_, this->gsmBer_);
140 return gsm.release();
141 }
142
Marshalling(Parcel & parcel) const143 bool GsmSignalInformation::Marshalling(Parcel &parcel) const
144 {
145 if (!parcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::GSM))) {
146 return false;
147 }
148 if (!parcel.WriteInt32(gsmRxlev_)) {
149 return false;
150 }
151 if (!parcel.WriteInt32(gsmBer_)) {
152 return false;
153 }
154 return true;
155 }
156
Unmarshalling(Parcel & parcel)157 std::unique_ptr<GsmSignalInformation> GsmSignalInformation::Unmarshalling(Parcel &parcel)
158 {
159 std::unique_ptr<GsmSignalInformation> signal = std::make_unique<GsmSignalInformation>();
160 if (signal && !signal->ReadFromParcel(parcel)) {
161 signal = nullptr;
162 }
163 return signal;
164 }
165
ReadFromParcel(Parcel & parcel)166 bool GsmSignalInformation::ReadFromParcel(Parcel &parcel)
167 {
168 if (!parcel.ReadInt32(gsmRxlev_)) {
169 return false;
170 }
171 if (!parcel.ReadInt32(gsmBer_)) {
172 return false;
173 }
174 return true;
175 }
176
ValidateGsmValue() const177 bool GsmSignalInformation::ValidateGsmValue() const
178 {
179 return gsmRxlev_ < SIGNAL_RSSI_MAXIMUM;
180 }
181
SetValue(const int32_t cdmaRssi,const int32_t cdmaEcno)182 void CdmaSignalInformation::SetValue(const int32_t cdmaRssi, const int32_t cdmaEcno)
183 {
184 cdmaRssi_ = cdmaRssi;
185 cdmaEcno_ = cdmaEcno;
186 }
187
operator ==(const CdmaSignalInformation & cdma) const188 bool CdmaSignalInformation::operator==(const CdmaSignalInformation &cdma) const
189 {
190 return (cdmaRssi_ == cdma.cdmaRssi_ && cdmaEcno_ == cdma.cdmaEcno_);
191 }
192
GetCdmaRssi() const193 int32_t CdmaSignalInformation::GetCdmaRssi() const
194 {
195 return cdmaRssi_;
196 }
197
GetSignalIntensity() const198 int32_t CdmaSignalInformation::GetSignalIntensity() const
199 {
200 int32_t signalIntensity = SIGNAL_INTENSITY_INVALID;
201
202 if (ValidateCdmaValue()) {
203 signalIntensity = GetCdmaRssi();
204 } else {
205 TELEPHONY_LOGE("CdmaSignalInformation::GetSignalIntensity Value is Invalid.");
206 }
207
208 return signalIntensity;
209 }
210
GetSignalLevel() const211 int32_t CdmaSignalInformation::GetSignalLevel() const
212 {
213 int32_t cdmaRssi = GetCdmaRssi();
214 int32_t level = SIGNAL_LEVEL_INVALID;
215 if (ValidateCdmaValue()) {
216 // Reference: TS 27.007 section 8.69
217 for (int32_t i = signalBar_; i >= 0; --i) {
218 if (cdmaRssi >= CDMA_SIGNAL_THRESHOLD[i]) {
219 level = i;
220 break;
221 }
222 }
223 }
224 return level;
225 }
226
GetNetworkType() const227 SignalInformation::NetworkType CdmaSignalInformation::GetNetworkType() const
228 {
229 return SignalInformation::NetworkType::CDMA;
230 }
231
ToString() const232 std::string CdmaSignalInformation::ToString() const
233 {
234 int32_t netWorkType = static_cast<int32_t>(CdmaSignalInformation::GetNetworkType());
235 std::string content(",networkType:" + std::to_string(netWorkType) + ",cdmaRssi:" + std::to_string(cdmaRssi_) +
236 ",cdmaEcno:" + std::to_string(cdmaEcno_) +
237 ",signalLevel:" + std::to_string(CdmaSignalInformation::GetSignalLevel()));
238 return content;
239 }
240
NewInstance() const241 sptr<SignalInformation> CdmaSignalInformation::NewInstance() const
242 {
243 std::unique_ptr<CdmaSignalInformation> cdma = std::make_unique<CdmaSignalInformation>();
244 if (cdma == nullptr) {
245 return nullptr;
246 }
247 cdma->SetValue(this->cdmaRssi_, this->cdmaEcno_);
248 return cdma.release();
249 }
250
Marshalling(Parcel & parcel) const251 bool CdmaSignalInformation::Marshalling(Parcel &parcel) const
252 {
253 if (!parcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::CDMA))) {
254 return false;
255 }
256 if (!parcel.WriteInt32(cdmaRssi_)) {
257 return false;
258 }
259 if (!parcel.WriteInt32(cdmaEcno_)) {
260 return false;
261 }
262 return true;
263 }
264
Unmarshalling(Parcel & parcel)265 std::unique_ptr<CdmaSignalInformation> CdmaSignalInformation::Unmarshalling(Parcel &parcel)
266 {
267 std::unique_ptr<CdmaSignalInformation> signal = std::make_unique<CdmaSignalInformation>();
268 if (signal && !signal->ReadFromParcel(parcel)) {
269 signal = nullptr;
270 }
271 return signal;
272 }
273
ReadFromParcel(Parcel & parcel)274 bool CdmaSignalInformation::ReadFromParcel(Parcel &parcel)
275 {
276 if (!parcel.ReadInt32(cdmaRssi_)) {
277 return false;
278 }
279 if (!parcel.ReadInt32(cdmaEcno_)) {
280 return false;
281 }
282 return true;
283 }
284
ValidateCdmaValue() const285 bool CdmaSignalInformation::ValidateCdmaValue() const
286 {
287 return cdmaRssi_ < SIGNAL_RSSI_MAXIMUM;
288 }
289
operator ==(const LteSignalInformation & lte) const290 bool LteSignalInformation::operator==(const LteSignalInformation <e) const
291 {
292 return rxlev_ == lte.rxlev_ && lteRsrp_ == lte.lteRsrp_ && lteRsrq_ == lte.lteRsrq_ && lteSnr_ == lte.lteSnr_;
293 }
294
SetValue(const int32_t rxlev,const int32_t lteRsrp,const int32_t lteRsrq,const int32_t lteSnr)295 void LteSignalInformation::SetValue(
296 const int32_t rxlev, const int32_t lteRsrp, const int32_t lteRsrq, const int32_t lteSnr)
297 {
298 rxlev_ = rxlev;
299 lteRsrp_ = lteRsrp;
300 lteRsrq_ = lteRsrq;
301 lteSnr_ = lteSnr;
302 }
303
GetRxlev() const304 int32_t LteSignalInformation::GetRxlev() const
305 {
306 return rxlev_;
307 }
308
GetRsrp() const309 int32_t LteSignalInformation::GetRsrp() const
310 {
311 return lteRsrp_;
312 }
313
GetRsrq() const314 int32_t LteSignalInformation::GetRsrq() const
315 {
316 return lteRsrq_;
317 }
318
GetSnr() const319 int32_t LteSignalInformation::GetSnr() const
320 {
321 return lteSnr_;
322 }
323
GetSignalIntensity() const324 int32_t LteSignalInformation::GetSignalIntensity() const
325 {
326 int32_t signalIntensity = SIGNAL_INTENSITY_INVALID;
327
328 if (ValidateLteValue()) {
329 signalIntensity = GetRsrp();
330 } else {
331 TELEPHONY_LOGE("LteSignalInformation::GetSignalIntensity Value is Invalid.");
332 }
333
334 return signalIntensity;
335 }
336
GetSignalLevel() const337 int32_t LteSignalInformation::GetSignalLevel() const
338 {
339 int32_t level = SIGNAL_LEVEL_INVALID;
340 int32_t lteRsrp = GetRsrp();
341 if (ValidateLteValue()) {
342 // Reference: TS 27.007 section 8.69
343 for (int32_t i = signalBar_; i >= 0; --i) {
344 if (lteRsrp >= LTE_SIGNAL_THRESHOLD[i]) {
345 level = i;
346 break;
347 }
348 }
349 } else {
350 TELEPHONY_LOGE("LteSignalInformation::GetSignalLevel Value is Invalid.");
351 }
352 return level;
353 }
354
GetNetworkType() const355 SignalInformation::NetworkType LteSignalInformation::GetNetworkType() const
356 {
357 return SignalInformation::NetworkType::LTE;
358 }
359
ToString() const360 std::string LteSignalInformation::ToString() const
361 {
362 int32_t netWorkType = static_cast<int32_t>(LteSignalInformation::GetNetworkType());
363 std::string content("networkType:" + std::to_string(netWorkType) + ",lteRsrp:" + std::to_string(lteRsrp_) +
364 ",lteRsrq:" + std::to_string(lteRsrq_) + ",lteSnr:" + std::to_string(lteSnr_) + ",lteRxlev:" +
365 std::to_string(rxlev_) + ",signalLevel:" + std::to_string(LteSignalInformation::GetSignalLevel()));
366 return content;
367 }
368
NewInstance() const369 sptr<SignalInformation> LteSignalInformation::NewInstance() const
370 {
371 std::unique_ptr<LteSignalInformation> lte = std::make_unique<LteSignalInformation>();
372 if (lte == nullptr) {
373 return nullptr;
374 }
375 lte->SetValue(this->rxlev_, this->lteRsrp_, this->lteRsrq_, this->lteSnr_);
376 return lte.release();
377 }
378
Marshalling(Parcel & parcel) const379 bool LteSignalInformation::Marshalling(Parcel &parcel) const
380 {
381 if (!parcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::LTE))) {
382 return false;
383 }
384 if (!parcel.WriteInt32(rxlev_)) {
385 return false;
386 }
387 if (!parcel.WriteInt32(lteRsrp_)) {
388 return false;
389 }
390 if (!parcel.WriteInt32(lteRsrq_)) {
391 return false;
392 }
393 if (!parcel.WriteInt32(lteSnr_)) {
394 return false;
395 }
396 return true;
397 }
398
Unmarshalling(Parcel & parcel)399 std::unique_ptr<LteSignalInformation> LteSignalInformation::Unmarshalling(Parcel &parcel)
400 {
401 std::unique_ptr<LteSignalInformation> signal = std::make_unique<LteSignalInformation>();
402 if (signal && !signal->ReadFromParcel(parcel)) {
403 signal = nullptr;
404 }
405 return signal;
406 }
407
ReadFromParcel(Parcel & parcel)408 bool LteSignalInformation::ReadFromParcel(Parcel &parcel)
409 {
410 if (!parcel.ReadInt32(rxlev_)) {
411 return false;
412 }
413 if (!parcel.ReadInt32(lteRsrp_)) {
414 return false;
415 }
416 if (!parcel.ReadInt32(lteRsrq_)) {
417 return false;
418 }
419 if (!parcel.ReadInt32(lteSnr_)) {
420 return false;
421 }
422 return true;
423 }
424
ValidateLteValue() const425 bool LteSignalInformation::ValidateLteValue() const
426 {
427 return lteRsrp_ < SIGNAL_RSSI_MAXIMUM;
428 }
429
operator ==(const WcdmaSignalInformation & wcdma) const430 bool WcdmaSignalInformation::operator==(const WcdmaSignalInformation &wcdma) const
431 {
432 return wcdmaRxlev_ == wcdma.wcdmaRxlev_ && wcdmaRscp_ == wcdma.wcdmaRscp_ && wcdmaEcio_ == wcdma.wcdmaEcio_ &&
433 wcdmaBer_ == wcdma.wcdmaBer_;
434 }
435
SetValue(const int32_t wcdmaRxlev,const int32_t wcdmaRscp,const int32_t wcdmaEcio,const int32_t wcdmaBer)436 void WcdmaSignalInformation::SetValue(
437 const int32_t wcdmaRxlev, const int32_t wcdmaRscp, const int32_t wcdmaEcio, const int32_t wcdmaBer)
438 {
439 wcdmaRxlev_ = wcdmaRxlev;
440 wcdmaRscp_ = wcdmaRscp;
441 wcdmaEcio_ = wcdmaEcio;
442 wcdmaBer_ = wcdmaBer;
443 }
444
GetRxlev() const445 int32_t WcdmaSignalInformation::GetRxlev() const
446 {
447 return wcdmaRxlev_;
448 }
449
GetRscp() const450 int32_t WcdmaSignalInformation::GetRscp() const
451 {
452 return wcdmaRscp_;
453 }
454
GetEcno() const455 int32_t WcdmaSignalInformation::GetEcno() const
456 {
457 return wcdmaEcio_;
458 }
459
GetBer() const460 int32_t WcdmaSignalInformation::GetBer() const
461 {
462 return wcdmaBer_;
463 }
464
GetSignalIntensity() const465 int32_t WcdmaSignalInformation::GetSignalIntensity() const
466 {
467 int32_t signalIntensity = SIGNAL_INTENSITY_INVALID;
468
469 if (ValidateWcdmaValue()) {
470 signalIntensity = GetRscp();
471 } else {
472 TELEPHONY_LOGE("WcdmaSignalInformation::GetSignalIntensity Value is Invalid.");
473 }
474
475 return signalIntensity;
476 }
477
GetSignalLevel() const478 int32_t WcdmaSignalInformation::GetSignalLevel() const
479 {
480 int32_t level = SIGNAL_LEVEL_INVALID;
481 int32_t wcdmaRscp = GetRscp();
482 if (ValidateWcdmaValue()) {
483 // Reference: TS 27.007 section 8.69
484 for (int32_t i = signalBar_; i >= 0; --i) {
485 if (wcdmaRscp >= WCDMA_SIGNAL_THRESHOLD[i]) {
486 level = i;
487 break;
488 }
489 }
490 } else {
491 TELEPHONY_LOGE("WcdmaSignalInformation::GetSignalLevel Value is Invalid.");
492 }
493 return level;
494 }
495
GetNetworkType() const496 SignalInformation::NetworkType WcdmaSignalInformation::GetNetworkType() const
497 {
498 return SignalInformation::NetworkType::WCDMA;
499 }
500
ToString() const501 std::string WcdmaSignalInformation::ToString() const
502 {
503 int32_t netWorkType = static_cast<int32_t>(WcdmaSignalInformation::GetNetworkType());
504 std::string content("networkType:" + std::to_string(netWorkType) + ",wcdmaRscp:" + std::to_string(wcdmaRscp_) +
505 ",wcdmaEcio:" + std::to_string(wcdmaEcio_) + ",wcdmaBer:" + std::to_string(wcdmaBer_) + ",wcdmaRxlev:" +
506 std::to_string(wcdmaRxlev_) + ",signalLevel:" + std::to_string(WcdmaSignalInformation::GetSignalLevel()));
507 return content;
508 }
509
NewInstance() const510 sptr<SignalInformation> WcdmaSignalInformation::NewInstance() const
511 {
512 std::unique_ptr<WcdmaSignalInformation> wcdma = std::make_unique<WcdmaSignalInformation>();
513 if (wcdma == nullptr) {
514 return nullptr;
515 }
516 wcdma->SetValue(this->wcdmaRxlev_, this->wcdmaRscp_, this->wcdmaEcio_, this->wcdmaBer_);
517 return wcdma.release();
518 }
519
Marshalling(Parcel & parcel) const520 bool WcdmaSignalInformation::Marshalling(Parcel &parcel) const
521 {
522 if (!parcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::WCDMA))) {
523 return false;
524 }
525 if (!parcel.WriteInt32(wcdmaRxlev_)) {
526 return false;
527 }
528 if (!parcel.WriteInt32(wcdmaRscp_)) {
529 return false;
530 }
531 if (!parcel.WriteInt32(wcdmaEcio_)) {
532 return false;
533 }
534 if (!parcel.WriteInt32(wcdmaBer_)) {
535 return false;
536 }
537 return true;
538 }
539
Unmarshalling(Parcel & parcel)540 std::unique_ptr<WcdmaSignalInformation> WcdmaSignalInformation::Unmarshalling(Parcel &parcel)
541 {
542 std::unique_ptr<WcdmaSignalInformation> signal = std::make_unique<WcdmaSignalInformation>();
543 if (signal && !signal->ReadFromParcel(parcel)) {
544 signal = nullptr;
545 }
546 return signal;
547 }
548
ReadFromParcel(Parcel & parcel)549 bool WcdmaSignalInformation::ReadFromParcel(Parcel &parcel)
550 {
551 if (!parcel.ReadInt32(wcdmaRxlev_)) {
552 return false;
553 }
554 if (!parcel.ReadInt32(wcdmaRscp_)) {
555 return false;
556 }
557 if (!parcel.ReadInt32(wcdmaEcio_)) {
558 return false;
559 }
560 if (!parcel.ReadInt32(wcdmaBer_)) {
561 return false;
562 }
563 return true;
564 }
565
ValidateWcdmaValue() const566 bool WcdmaSignalInformation::ValidateWcdmaValue() const
567 {
568 return wcdmaRscp_ < SIGNAL_RSSI_MAXIMUM;
569 }
570
operator ==(const TdScdmaSignalInformation & tdScdma) const571 bool TdScdmaSignalInformation::operator==(const TdScdmaSignalInformation &tdScdma) const
572 {
573 return tdScdmaRscp_ == tdScdma.tdScdmaRscp_;
574 }
575
SetValue(const int32_t tdScdmaRscp)576 void TdScdmaSignalInformation::SetValue(const int32_t tdScdmaRscp)
577 {
578 tdScdmaRscp_ = tdScdmaRscp;
579 }
580
GetRscp() const581 int32_t TdScdmaSignalInformation::GetRscp() const
582 {
583 return tdScdmaRscp_;
584 }
585
GetSignalIntensity() const586 int32_t TdScdmaSignalInformation::GetSignalIntensity() const
587 {
588 int32_t signalIntensity = SIGNAL_INTENSITY_INVALID;
589
590 if (ValidateTdScdmaValue()) {
591 signalIntensity = GetRscp();
592 } else {
593 TELEPHONY_LOGE("TdScdmaSignalInformation::GetSignalIntensity Value is Invalid.");
594 }
595
596 return signalIntensity;
597 }
598
GetSignalLevel() const599 int32_t TdScdmaSignalInformation::GetSignalLevel() const
600 {
601 int32_t tdScdmaRscp = GetRscp();
602 int32_t level = SIGNAL_LEVEL_INVALID;
603 if (ValidateTdScdmaValue()) {
604 // Reference: TS 27.007 section 8.69
605 for (int32_t i = signalBar_; i >= 0; --i) {
606 if (tdScdmaRscp >= TD_SCDMA_SIGNAL_THRESHOLD[i]) {
607 level = i;
608 break;
609 }
610 }
611 }
612 return level;
613 }
614
GetNetworkType() const615 SignalInformation::NetworkType TdScdmaSignalInformation::GetNetworkType() const
616 {
617 return SignalInformation::NetworkType::TDSCDMA;
618 }
619
ToString() const620 std::string TdScdmaSignalInformation::ToString() const
621 {
622 int32_t netWorkType = static_cast<int32_t>(TdScdmaSignalInformation::GetNetworkType());
623 std::string content("networkType:" + std::to_string(netWorkType) + ",tdScdmaRscp:" + std::to_string(tdScdmaRscp_) +
624 ",signalLevel:" + std::to_string(TdScdmaSignalInformation::GetSignalLevel()));
625 return content;
626 }
627
NewInstance() const628 sptr<SignalInformation> TdScdmaSignalInformation::NewInstance() const
629 {
630 std::unique_ptr<TdScdmaSignalInformation> tdScdma = std::make_unique<TdScdmaSignalInformation>();
631 if (tdScdma == nullptr) {
632 return nullptr;
633 }
634 tdScdma->SetValue(this->tdScdmaRscp_);
635 return tdScdma.release();
636 }
637
Marshalling(Parcel & parcel) const638 bool TdScdmaSignalInformation::Marshalling(Parcel &parcel) const
639 {
640 if (!parcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::TDSCDMA))) {
641 return false;
642 }
643 if (!parcel.WriteInt32(tdScdmaRscp_)) {
644 return false;
645 }
646 return true;
647 }
648
Unmarshalling(Parcel & parcel)649 std::unique_ptr<TdScdmaSignalInformation> TdScdmaSignalInformation::Unmarshalling(Parcel &parcel)
650 {
651 std::unique_ptr<TdScdmaSignalInformation> signal = std::make_unique<TdScdmaSignalInformation>();
652 if (signal && !signal->ReadFromParcel(parcel)) {
653 signal = nullptr;
654 }
655 return signal;
656 }
657
ReadFromParcel(Parcel & parcel)658 bool TdScdmaSignalInformation::ReadFromParcel(Parcel &parcel)
659 {
660 if (!parcel.ReadInt32(tdScdmaRscp_)) {
661 return false;
662 }
663 return true;
664 }
665
ValidateTdScdmaValue() const666 bool TdScdmaSignalInformation::ValidateTdScdmaValue() const
667 {
668 return tdScdmaRscp_ < SIGNAL_RSSI_MAXIMUM;
669 }
670
operator ==(const NrSignalInformation & nr) const671 bool NrSignalInformation::operator==(const NrSignalInformation &nr) const
672 {
673 return nrRsrp_ == nr.nrRsrp_ && nrRsrq_ == nr.nrRsrq_ && nrSinr_ == nr.nrSinr_;
674 }
675
SetValue(const int32_t rsrp,const int32_t rsrq,const int32_t sinr)676 void NrSignalInformation::SetValue(const int32_t rsrp, const int32_t rsrq, const int32_t sinr)
677 {
678 nrRsrp_ = rsrp;
679 nrRsrq_ = rsrq;
680 nrSinr_ = sinr;
681 }
682
GetRsrp() const683 int32_t NrSignalInformation::GetRsrp() const
684 {
685 return nrRsrp_;
686 }
687
GetRsrq() const688 int32_t NrSignalInformation::GetRsrq() const
689 {
690 return nrRsrq_;
691 }
692
GetSinr() const693 int32_t NrSignalInformation::GetSinr() const
694 {
695 return nrSinr_;
696 }
697
GetSignalIntensity() const698 int32_t NrSignalInformation::GetSignalIntensity() const
699 {
700 int32_t signalIntensity = SIGNAL_INTENSITY_INVALID;
701
702 if (ValidateNrValue()) {
703 signalIntensity = GetRsrp();
704 } else {
705 TELEPHONY_LOGE("NrSignalInformation::GetSignalIntensity Value is Invalid.");
706 }
707
708 return signalIntensity;
709 }
710
GetSignalLevel() const711 int32_t NrSignalInformation::GetSignalLevel() const
712 {
713 int32_t nrRsrp = GetRsrp();
714 int32_t level = SIGNAL_LEVEL_INVALID;
715 if (ValidateNrValue()) {
716 // Reference: TS 27.007 section 8.69
717 for (int32_t i = signalBar_; i >= 0; --i) {
718 if (nrRsrp >= NR_SIGNAL_THRESHOLD[i]) {
719 level = i;
720 break;
721 }
722 }
723 }
724 return level;
725 }
726
GetNetworkType() const727 SignalInformation::NetworkType NrSignalInformation::GetNetworkType() const
728 {
729 return SignalInformation::NetworkType::NR;
730 }
731
ToString() const732 std::string NrSignalInformation::ToString() const
733 {
734 int32_t netWorkType = static_cast<int32_t>(NrSignalInformation::GetNetworkType());
735 std::string content("networkType:" + std::to_string(netWorkType) + ",nrRsrp:" + std::to_string(nrRsrp_) +
736 ",nrRsrq:" + std::to_string(nrRsrq_) + ",nrSinr:" + std::to_string(nrSinr_) +
737 ",signalLevel:" + std::to_string(NrSignalInformation::GetSignalLevel()));
738 return content;
739 }
740
NewInstance() const741 sptr<SignalInformation> NrSignalInformation::NewInstance() const
742 {
743 std::unique_ptr<NrSignalInformation> nr = std::make_unique<NrSignalInformation>();
744 if (nr == nullptr) {
745 return nullptr;
746 }
747 nr->SetValue(this->nrRsrp_, this->nrRsrq_, this->nrSinr_);
748 return nr.release();
749 }
750
Marshalling(Parcel & parcel) const751 bool NrSignalInformation::Marshalling(Parcel &parcel) const
752 {
753 if (!parcel.WriteInt32(static_cast<int32_t>(SignalInformation::NetworkType::NR))) {
754 return false;
755 }
756 if (!parcel.WriteInt32(nrRsrp_)) {
757 return false;
758 }
759 if (!parcel.WriteInt32(nrRsrq_)) {
760 return false;
761 }
762 if (!parcel.WriteInt32(nrSinr_)) {
763 return false;
764 }
765 return true;
766 }
767
Unmarshalling(Parcel & parcel)768 std::unique_ptr<NrSignalInformation> NrSignalInformation::Unmarshalling(Parcel &parcel)
769 {
770 std::unique_ptr<NrSignalInformation> signal = std::make_unique<NrSignalInformation>();
771 if (signal && !signal->ReadFromParcel(parcel)) {
772 signal = nullptr;
773 }
774 return signal;
775 }
776
ReadFromParcel(Parcel & parcel)777 bool NrSignalInformation::ReadFromParcel(Parcel &parcel)
778 {
779 if (!parcel.ReadInt32(nrRsrp_)) {
780 return false;
781 }
782 if (!parcel.ReadInt32(nrRsrq_)) {
783 return false;
784 }
785 if (!parcel.ReadInt32(nrSinr_)) {
786 return false;
787 }
788 return true;
789 }
790
ValidateNrValue() const791 bool NrSignalInformation::ValidateNrValue() const
792 {
793 return nrRsrp_ < SIGNAL_RSSI_MAXIMUM;
794 }
795 } // namespace Telephony
796 } // namespace OHOS
797